The locate command searches a database of file paths rather than scanning the filesystem each time you run it. This can make searches quick, but the results depend on when the database was last updated and which directories it includes.
Install locate
Open a terminal or connect to your Linux server using SSH. Installing packages and updating the system-wide database require administrative access.
Several packages provide locate. On Debian 13, install plocate:
sudo apt update
sudo apt install plocateOn Red Hat Enterprise Linux 9, install mlocate:
sudo dnf install mlocateFor other distributions, check which package is available in your distribution’s repositories. The examples below use options supported by both plocate and mlocate.
Update the database
Run the following command after installation, or when you need recently added files to appear in the results:
sudo updatedbWait for the command to finish before searching. Automatic update schedules and excluded directories depend on the system configuration. A missing database error usually means that the database has not yet been created.
Search for files
Search for paths containing a name:
locate filenameSearch for paths ending in .txt:
locate '*.txt'Keep wildcard patterns in quotes so that your shell passes them to locate unchanged.
Use search options
Ignore differences between upper-case and lower-case letters:
locate -i readmeUse a regular expression to find .log files below /home/user. Replace this example directory with the one you need:
locate -r '^/home/user/.*\.log$'Count matching paths instead of listing them:
locate -c backupUnderstand the results
New files may be absent until the next database update. Deleted files may still appear in an older database. Files in excluded directories, or paths you do not have permission to access, may also be absent. An empty result therefore does not establish that a file does not exist.