On Unix-like operating systems, the locate command finds files by name.

This page covers the GNU/Linux version of locate.

Description

locate reads one or more databases prepared by updatedb and writes file names matching at least one of the PATTERNs to standard output, one per line.

  • Description
  • Syntax
  • Examples
  • Related commands
  • Linux commands help

If –regex is not specified, PATTERNs can contain globbing characters. If any PATTERN contains no globbing characters, locate behaves as if the pattern were “PATTERN”.

By default, locate does not check whether files found in database still exist (but it does require all parent directories to exist if the database was built with “–require-visibility no”). locate can never report files created after the most recent update of the relevant database.

Syntax

locate [OPTION]… PATTERN…

Options

Exit Status

locate exits successfully with status 0 if:

  • any match was found, or
  • the command was invoked with one of the –limit 0, –help, –statistics or –version options, because those options cause it not to search for anything at all. Therefore, even though locate did not match any results, the command exits successfully.

locate exits unsuccessfully with status 1 if:

  • no match was found, or
  • a fatal error was encountered, causing the program to terminate.

Examples

locate perl

Locates files named perl on the local machine.

Errors encountered while reading a database are not fatal; search continues in other specified databases, if any.

find — Find files within a directory hierarchy.whereis — Locate the binary, source, and manual page files for a command.xargs — Build and execute complex commands, and execute them on multiple files.