Use locate to quickly find files on Linux

Use locate to quickly find files on Linux

locate is a great way to quickly find files on your system. It searches using an index created using the updatedb utility so it can find files much more quickly than find can.

The downside is that it won’t look for files that have changed since the last time you’ve run updatedb. On most systems this runs every day, but you can run it manually if you need to find a recently made file.

Below is a forced example, pitting find at it’s worse searching through everything:

# time find / -name "firefox"

real 1m3.834s
user 0m0.683s
sys 0m2.107s

# time locate firefox


real 0m0.435s
user 0m0.417s
sys 0m0.007s

In this case, locate is much faster. It also spits out a good deal more results than find does, so piping it into less or grep can be rather handy.

When you know what you’re looking for or need up to date information on what files are where, find will typically be much faster:

# time find /usr/bin/ -name "firefox"

real 0m0.008s
user 0m0.007s
sys 0m0.000s

Further Reading:

man find
man locate

Online versions of these two man pages can be found at: