locate
Files and directories
Usage
locate [name]Searches a prebuilt index instead of the disk, so it answers instantly but cannot see files created since the last updatedb.
Common flags
| Flag | Meaning |
|---|---|
| -i | Ignore case |
| -l | Stop after N results |
| -c | Print only how many matched |
| -b | GNU mlocate: match the file name, not the whole path |
| -r | GNU: read the pattern as a regular expression |
| -e | GNU: skip entries that no longer exist on disk |
Examples
locate -i nginx.confFinds the config anywhere on disk, instantly.
sudo updatedbRebuilds the index so new files can be found.
Moving, deleting and finding. Some of these do not ask twice, which is why -i becomes a habit.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does locate do?
Searches a prebuilt index instead of the disk, so it answers instantly but cannot see files created since the last updatedb.
Q. How do I type it?
locate [name] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man locate. This command sits under Files and directories.
Related commands
man page: man locate