locate your files!

This is just a quick set of tips about the super-duper-handy locate command at, well, the command line.

First off, it’s called locate. If you don’t have it installed, it may be contained in a package called findutils-locate (a “shout-out” to all my fellow SUSE distro users)

Secondly, to manually update the locate command’s database (it automatically runs each night), you type (as root): updatedb …and wait for a while.

Thirdly, in your shell of choice, alias locate='locate -i' …and you’ll get case-insensitive locate! Combined with grep (especially grep -i; i also happens to be its case-insensitive flag too), you’ll be finding files in your hard drive quite easy from now on…

I use locate all the time, especially whenever I’m looking for a quick path to find a graphic I of which know the filename (or part of a filename). For example:

locate information | grep png | grep 48

Will return something like (depending on your distribution):


Tags: , , , ,

11 Responses to “locate your files!”

  1. baptiste says:

    and what about beagle šŸ™‚
    /me runs

  2. BenoƮt says:

    Use slocate !

    locate is unsecured.

    “Secure Locate provides a secure way to index and quickly search for all files on your system regardless of ownership.”

  3. James says:

    Benoit, you have misunderstood the difference between slocate and locate. It’s not that one is secure and the other is not, really.

  4. bill says:

    Locate? Bah! Try rlocate – it really makes a diff on multiple levels

  5. @Benoit:
    Distributions like redhat install slocate instead of locate. The binary name is *still* locate. The only difference is that slocate allows your to view path and filenames in directories your user wouldn’t normally have access to. Not a huge security hole, but might be something sensitive.

    A better way to do it

    locate information | grep ’48.*png’

  6. garrett says:

    Thanks! That seems so obvious, but I was doing something that just worked. That’ll save a lot of typing.

    I already know the filename; I don’t need to search the content. Beagle is excellent for finding files in which you might forget the filename, but it doesn’t work so well for graphics. There’s beagle-query for all your command-line beagle needs.

  7. BenoƮt says:

    luke$ locate mother

    It is a security hole because it provides you information that you are not authorized to have.

  8. I’ve used slocate for a long time, and love it. It also supports locating files by regexps:

    $ locate -i -r information.*48.*png$

    There’s also dlocate, which has a faster version of dpkg -S (finding installed packages that contain a filename).

  9. baptiste says:

    Appart from my little message about beagle, it’s funny that people who “work” to make desktop better on Unix, give tips to be powerful in command-line :).

    I didn’t try on gnome-search-tool, but from what I recall, it can search in the locate database; I’m not sure though that it is possible to perform search like this.

  10. Nothing beats the commandline when you have learned it well. There’s just a big learning curve.

Leave a Reply