Skip to content

Linux locate command (find files)

The locate command can be used to find files on the system through a database that it maintains. Since it searches a database, the result is instantaneous. However, files recently added to the disk may not be in the database yet.

In this way, the database can be updated from time to time, or manually.

Example:

$ locate passwd /etc/passwd /etc/passwd- /etc/pam.d/passwd /etc/security/opasswd /usr/bin/gpasswd (...)

To update the database, the updatedb command must be run by root:

$ sudo updatedb

The locate command is not always installed as standard in distributions, which can be done with the apt or yum commands, depending on the distribution:

For Debian or Ubuntu distributions:

$ sudo apt install locate

For Red Hat/CentOS/Fedora:

$ sudo yum install locate

Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it?

Share