Home·Terminal commands

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

FlagMeaning
-iIgnore case
-lStop after N results
-cPrint only how many matched
-bGNU mlocate: match the file name, not the whole path
-rGNU: read the pattern as a regular expression
-eGNU: skip entries that no longer exist on disk

Examples

locate -i nginx.conf

Finds the config anywhere on disk, instantly.

sudo updatedb

Rebuilds 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