$linuxjunkies
>

locate(1)

Find files by name using a pre-built database of the filesystem.

UbuntuDebianFedoraArch

Synopsis

locate [OPTION]... PATTERN

Description

locate searches a database of file and directory names for entries matching the given pattern. It is much faster than find because it uses a pre-built index rather than scanning the filesystem in real time. The database is typically updated daily by a cron job.

By default, locate returns all pathnames containing the pattern as a substring, matching in a case-insensitive manner. Patterns can include shell-style wildcards like * and ?.

Common options

FlagWhat it does
-icase-insensitive matching (default behavior)
-ccount matching entries instead of printing them
-rinterpret pattern as a basic regular expression
-eexclude entries matching the given pattern from results
-llimit output to a specific number of results
-Sprint database statistics and exit
-dspecify a custom database path instead of the default
-wmatch only whole path components (separated by /)

Examples

Find all files and directories named or containing 'nginx.conf'

locate nginx.conf

Count how many log files exist in the database

locate -c *.log

Find files matching 'passwd' (case-insensitive, finds passwd and PASSWD)

locate -i PASSWD

Use regex to find all .conf files under /etc/

locate -r '^/etc/.*\.conf$'

Find all paths containing 'python' and show first 20 results

locate python | head -20

Find /usr/bin/python3 only if it currently exists (verify with -e)

locate -e /usr/bin/python3

Related commands