How to 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. On most CentOS/RHEL systems, findutils comes pre-installed, however, if you try to run a locate command, you may encounter the error:

-bash: locate: command not found

In this article, we will show you how to install mlocate package which provides the locate and updatedb commands to find files in Linux systems.

Below is a sample output showing the above error and querying findutils package.

$ locate bash_completion.sh
$ rpm -qa | grep findutils
Locate Command Not Found

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]     

After installing mlocate, you need to update the updatedb, which is used by locate command as root user with the sudo command, otherwise you will get an error. The default database storage location is /var/lib/mlocate/mlocate.db.

$ sudo updatedb

Once the database is updated, now try to run the locate command, which should work this time around.

$ locate bash_completion.sh
Find Files Using Locate Command

Find Files Using Locate Command

To find an exact match according to pattern you enter, use this -b option and the \ globbing option as in the following syntax.

$ locate -b '\bash_completion.sh'

Note: You can use the LOCATE_PATH environmental variable to set a path to extra databases, which are read after the default database or any databases listed using the –database flag on the command line.

That’s all! In this guide, we showed you how to install mlocate package which offers the locate and updatedb commands on a Linux system. Share your views with us through the feedback form below.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

4 Responses

  1. Ivan says:

    Solved my problem!
    Thank you a lot!

  2. tim says:

    Brilliant, thank you.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.