Sunday, November 18, 2018

Install ‘locate Command’ to Find Files in Linux

The locate is a command line utility for finding files by name in Linux, just like find command. However, it works more efficiently compared to its counterpart; it uses one or more databases populated by the updatedb program and prints file names matching at least one of the patterns (a user provides) to standard output.

Locate package is provided by the GNU findutils or mlocate packages. These packages are known to provide the same implementation of the program.

If you try to run a locate command, you may encounter the error:
# locate which
bash: locate: command not found

To install mlocate, use the YUM or APT package manager as per your Linux distribution as shown.

$ sudo yum install mlocate    [On CentOS/RHEL]
$ sudo apt install mlocate    [On Debian/Ubuntu]     

[root@dfdf41f1677a /]# locate which
locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
[root@dfdf41f1677a /]# updatedb