locate(1)
Find files by name using a pre-built database of the filesystem.
Synopsis
locate [OPTION]... PATTERNDescription
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
| Flag | What it does |
|---|---|
-i | case-insensitive matching (default behavior) |
-c | count matching entries instead of printing them |
-r | interpret pattern as a basic regular expression |
-e | exclude entries matching the given pattern from results |
-l | limit output to a specific number of results |
-S | print database statistics and exit |
-d | specify a custom database path instead of the default |
-w | match only whole path components (separated by /) |
Examples
Find all files and directories named or containing 'nginx.conf'
locate nginx.confCount how many log files exist in the database
locate -c *.logFind files matching 'passwd' (case-insensitive, finds passwd and PASSWD)
locate -i PASSWDUse 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 -20Find /usr/bin/python3 only if it currently exists (verify with -e)
locate -e /usr/bin/python3