Find files on your system using ‘locate’

Locating files that you know exist, but you can't remember where they are can be frustrating. There are a handful of GUI-based search tools for Linux and Unix, but if you prefer to work in the command line, or don't have one of these special apps installed, you can often fall back on command line tool locate.

The locate command works by querying a database of your files. It won't be very useful, unfortunately, unless this database is kept up to date. What I recommend you do is set up a cron job to run the /usr/bin/updatedb command (as root) every day/night so that the locate tool becomes useful.

Some distributions have taken the liberty of scheduling updatedb for you already, so you might find this step unnecessary and you can get straight to the searching.

Once you have the database in place, locating a file is as simple as this:

$ locate alostfile

If there are no results, you will be just sent back to a prompt, and you will need to widen or refine your search. Any results will be spat back out as a list of the paths to the files that it has found.

This method of searching works best when you do actually know the filename, or part of it, and as far as I'm aware doesn't look in the contents of files to search.

Nevertheless, if you have lost that important file and don't have an alternative desktop search program already installed, give locate a try.

Avatar for peter Peter Upfold - http://peter.upfold.org.uk/

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Find files on your system using ‘locate’

  1. # Posted on 05 April 2008 at 05:35 AM

    [...] Original:http://fosswire.com/2008/04/04/find-files-on-your-system-using-locate/ [...]



  2. # Posted on 06 April 2008 at 09:47 AM

    <strong>Story added...</strong>

    This story has been submitted to fsdaily.com! If you think this story should be read by the free software community, come vote it up and discuss it here:

    http://www.fsdaily.com/Beginner/Find_files_on_your_system_using_locate...



Home » Articles » Find files on your system using ‘locate’