Open In App

Linux – Installing locate Command to Find Files

In this article, we will see how to install locate command to find files in Linux. locate is a command-line interface tool used for finding files by name in Linux systems. This works more efficiently than other commands. It uses one or more databases by updatedb. 

To check whether locate utility is already installed in your system. Open up your terminal and type.



locate 

If the system produces the output “locate: no pattern to search for specified” Then here locate package is installed like in the below image.



Otherwise, we will see something like “locate command not found” like in the below image.

mlocate package which provides the locate and updatedb commands to find files in Linux systems. To install it use the following commands:

For Ubuntu And Debian:

sudo apt install mlocate

For CentOS and Fedora 

sudo yum install mlocate

During the installation of the mlocate package, a “cron job” is created that runs updatedb command every 24 hours. So even we can manually update the updatedb as the root user or with sudo.

sudo updatedb 

This command may take some time to complete depending upon no. of files, directories, and speed of our system. So Files created after the database update will not be shown in the locate Command results.

Now we will try to run the locate command. Suppose if you want to search a file with a particular extension like in the below example:

locate .bashrc

Suppose if you want to find an exact match according to the pattern you enter, we should use the “-b” option and the “\” globbing option as in the following syntax.

locate -b '\bash.list'

Article Tags :