Search Files Recursively With Locate in Linux

Last updated on Dec 30, 2019 in Linux

If you are not sure where the file could be found in your Linux file system, you can use efficient locate command. It store information about file locations in embedded database, so locating any file is very fast.

In this example, we want to find a file config.ini, which can be anywhere in the system.

Install Locate

You can skip this if it is already installed.

$ sudo yum install mlocate // CentOS/RHEL
$ sudo apt-get install mlocate // Debian/Ubuntu

Update Database (updatedb)

This updates the built-in database with data about the whole file system. You must do this after the installation, but otherwise it is run automatically by cron job, so you normally don’t have to care about it.

$ sudo updatedb

Search File (locate)

Once the database is updated, you can search files easily:

$ locate config.ini

The ouput is found files with full paths.

You can also do normal wildcard searches:

$ locate *.ini