Jump to content

Recommended Posts

Posted

<div class="KonaBody"><p><img src="http://osxdaily.com/wp-content/uploads/2011/11/locate-command-mac.jpg" alt="locate command in Mac OS X" title="locate-command-mac" width="620" height="410" class="aligncenter size-full wp-image-23273" /></p>

<p>The locate command is very useful if you’re looking to track down every instance of a file, filetype, app, extension, things hidden deep in system folders, or just about anything else that Spotlight can’t manage. It’s extraordinarily useful for troubleshooting and even more mundane tasks like completely <a href="http://osxdaily.com/2011/06/20/uninstall-mac-applications/">uninstalling Mac apps</a>. </p>

<p>In order to use locate, you need to build the locate database, which also enables a few other helpful commands including whatis, find, and the manual keyword search ‘man -k’. OS X 10.7 is better at building this for you, but if you don’t have locate enabled yet all that is required is typing this command into the Terminal:</p>

<p><code> sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist</code></p>

<p>This is told to you directly by OS X the first time you attempt to run locate or any of the commands dependent on the database:</p>

<blockquote><p>$ locate python</p>

<p>WARNING: The locate database (/var/db/locate.database) does not exist.

To create the database, run the following command:</p>

<p> sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist</p>

<p>Please be aware that the database can take some time to generate; once

the database has been created, this message will no longer appear.

</p></blockquote>

<p>How long it takes to generate the database varies, but the larger your hard disk the longer it’ll be. You can watch the progress indirectly through <a href="http://osxdaily.com/2010/08/15/mac-task-manager/">Activity Monitor</a>, where the “find” process will be running at around 15-30% CPU use until the locate database is generated.</p>

<p><img src="http://osxdaily.com/wp-content/uploads/2011/11/find-process-locate.jpg" alt="find process running to build locate db" title="find-process-locate" width="613" height="132" class="aligncenter size-full wp-image-23272" /></p>

<p>Alternatively you can also run the following command and build the database:</p>

<p><code>sudo /usr/libexec/locate.updatedb</code></p>

<p>As with many terminal commands, locate accepts wildcards and regular expressions, helping you narrow down advanced searches. For example, you could find every possible file with a .jpg extension by using:</p>

<p><code>locate *.jpg</code></p>

<p>Some jpg files will inevitably have an uppercase extension though, and you can tell locate to ignore case sensitivity with -i:</p>

<p><code>locate -i *.jpg</code></p>

<p>There are plenty of other options you can work with, refer to ‘man locate’ for more info.</p>

<p><a href="http://osxdaily.com/category/command-line/">Don’t forget to check out more OS X command line tips too</a>.</p>

</div>

<p><a href="http://feedads.g.doubleclick.net/~a/ltaJ8vLe4wxasTbPV639mVhd9EA/0/da"><img src="http://feedads.g.doubleclick.net/~a/ltaJ8vLe4wxasTbPV639mVhd9EA/0/di" border="0" ismap="true"></img></a><br/>

<a href="http://feedads.g.doubleclick.net/~a/ltaJ8vLe4wxasTbPV639mVhd9EA/1/da"><img src="http://feedads.g.doubleclick.net/~a/ltaJ8vLe4wxasTbPV639mVhd9EA/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">

<a href="http://feeds.feedburner.com/~ff/osxdaily?a=r3yqO1dxkXM:bRSsSHoAaS4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=r3yqO1dxkXM:bRSsSHoAaS4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=r3yqO1dxkXM:bRSsSHoAaS4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=r3yqO1dxkXM:bRSsSHoAaS4:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=r3yqO1dxkXM:bRSsSHoAaS4:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=r3yqO1dxkXM:bRSsSHoAaS4:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=r3yqO1dxkXM:bRSsSHoAaS4:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=qj6IDK7rITs" border="0"></img></a>

</div><img src="http://feeds.feedburner.com/~r/osxdaily/~4/r3yqO1dxkXM" height="1" width="1"/>

 

View the full article

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days


×
×
  • Create New...