locate
Explanation
The locate command reads one or more databases prepared by updatedb and writes file names matching at least one of the patterns to standard output. Because it queries a pre-built database rather than searching the live filesystem like find, it is incredibly fast. However, it will not find files created after the last database update.
Basic Syntax
locate [OPTION]... PATTERN...
Common Flags and Options
| Flag | Description |
|---|---|
-i, --ignore-case | Ignore case distinctions when matching patterns. |
-c, --count | Instead of printing matched filenames, just print the number of matches. |
-l, --limit, -n LIMIT | Limit output (or counting) to LIMIT matches. |
-e, --existing | Print only entries that refer to files existing at the time locate is run. |
Real-world Examples
-
Find a file by part of its name:
locate sshd_config -
Find a file case-insensitively:
locate -i readme.txt -
Count the number of MP3 files on the system:
locate -c "*.mp3"