What’s the difference between locate and find command in Linux

Two popular commands for locating files on Linux are find and locate. Depending on the size of your file system and the depth of your search, the find command can sometime take a long time to scan all of the data. For example, if you search your entire filesystem for the files named data.txt:

# find / -name data.txt

More likely than not, this will take on the order of minutes, if not longer to return. A quicker method is to use the locate command:

# locate data.txt

However, this efficiency comes at a cost, the data reported in the output of locate isn’t as fresh as the data reported by the find command. By default, the system will run updatedb which takes a snapshot of the system files once a day, locate uses this snapshot to quickly report what files are where. However, recent file additions or removals (within 24 hours) are not recorded in the snapshot and are unknown to locate.

The find command has a number of options and is very configurable. There are many ways to reduce the depth and breadth of your search and make it more efficient.

locate uses a previously built database, If database is not updated then locate command will not show the output. to sync the database it is must to execute updatedb command.

# updatedb
Related Post