Back to the command reference

locate

FilesFundamentals In simulator In real Linux

Find files by name using a prebuilt index

Name: locate

You can practise it right away in the simulator, and use it in real Linux mode too.

Description

locate searches a prebuilt database of file names, so results come back almost instantly. The database is usually refreshed daily, so new files may be missing until you run sudo updatedb.

On modern distributions it comes from the mlocate or plocate package.

Syntax

locate [OPTION]... PATTERN...

Common options

-i / --ignore-caseIgnore case
-c / --countOnly print the number of matches
-l / --limit NShow at most N results
-b / --basenameMatch only the last part of the path
-e / --existingShow only files that still exist (the database may be old)
-r / --regex REGEXMatch a regular expression

Examples

  • $ locate nginx.conf

    Find a file instantly (faster than find)

    Explain
  • $ sudo updatedb

    Refresh the index so new files show up

    Explain

Related