Ubuntu – Difference among “whereis ” , “locate ” and “find”command

command linefindlocate

What are the differences among whereis , locate and findcommands on Ubuntu ? What are the basic differences from the searching point of view ?

Best Answer

From GNU findutils help page

The find program searches a directory tree to find a file or group of files. It traverses the directory tree and reports all occurrences of a file matching the user's specifications. The find program includes very powerful searching capability.

The locate program scans one or more databases of filenames and displays any matches. This can be used as a very fast find command if the file was present during the last file name database update.

So find is what you use when you want to search by particular criteria and also manipulate files. It has many more options than locate so allows far more fine-grained control of results. It is slow because it performs the requested test(s) on every file to see if it matches.

locate is used to scan the whole system quickly for something - you might use this when you have no idea where something is, or when you want to find all related files scattered across various unknown places. It's fast because it uses a binary database to index the system. To get new files to show up, first run sudo updatedb (the database it updated once per day by cron

the whereis command simply returns the location of the executables, the man pages and the sources of a program (see man whereis)