command line, linux

find vs locate

In terms of searching files in Linux, two the most popular tools are find and locate. Although there are significant differences between them.

According to man pages:

locate -- find filenames quickly

find -- walk a file hierarchy

locate program searches a regularly created database for all pathnames which match specified pattern. The database is updated by default once a day. This can be checked by looking for mlocate file in /etc/cron.daily

On the other hand, find searches through the directory tree given in command.

Summary

find is slower, but it searches for files in real time and has much more flexibility if we have to apply complex filtering.

locate uses read-only database which has indexes of the directory structure. So it brings to searching for a string in a file.

Remember, if file does not appear in locate search results, but do in find, you can update mlocate db manually by running updatedb