In Linux, there are a variety of commands to locate files, each with its own set of advantages and disadvantages. Some are only available in certain distributions, and others are not installed by default.
Let’s start with the quickest approach to find files with locate, and then go on to find: a very powerful application that is available in virtually all Linux distributions to help users in finding files.
locate
Usage | locate <what you are looking for> |
Advantages | Looks through a database, therefore, is really fast |
Disadvantages | the database has to be updated in order to find new files |
Install:
yum install mlocate
Then update the database with the command:
sudo updatedb && locate -e bench-repo
Otherwise you will get an error: locate: can not stat () `/var/lib/mlocate/mlocate.db’: No such file or directory
Example:
locate whois
find
Usage | find <path> -name “<what you are looking for>” |
Advantages | No database to use and has lots of advanced features |
Disadvantages | Can be slow and requires more typing even for a simple search |
Example:
Search for exact matches of “whois”
find / -name "whois"
Search for files that have “whois” in their name
find / -name "*whois*"
Both of the above methods used for finding files in Linux can have many parameters. You can read the man page of locate or man page for find to read more ways to run the commands to find files.