Difference among "whereis " , "locate " and "find"command
Solution 1:
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
)
Solution 2:
Big difference is that find
searches real files recursively down a given directory, while locate
searches a database without requiring specific directory. Thus, if you have saved a file before updating database, find
will find it , but locate
won't.
As for whereis
and which
, they search only inside those directories that are mentioned in your PATH variable and only those with executable permission set