The find
command is normally used to search for files starting from the current directory. The locate
command uses the updatedb
database to find files or directories on the entire system (with some exceptions).
Let's use find
and locate
to look for some common Linux files:
First change the directory to
/usr
:cd /usr
Run the following command:
find -name bash
Now try it with a wildcard:
find -name bash*
It will also find directories:
find -name bin
Now suppose we want to look for a file, but don't really know where it might be on the system. The find
command is also slow at times, because it has to search the filesystem from the current point. Here's where locate
comes in real handy.
You can be in any directory for this example. Run the following command:
locate gnome-terminal
Now try the command:
locate vim
See how fast this is? Now try:
locate ifconfig
To ignore case do:
locate -i sudo