locate – Linux, Unix Command


locate command finds files by name. This command is fast because it has contents that is stored in the database. On regular basis locate runs a cron that updates the system. So instead of having search the entire system when you use locate. It is searching the database. Remember, the database must always be up-to-date if you want to find recently created files.

The database can be updated manually by typing the following command:





1.) This command locates files named hello on the system.

locate hello

2.) This command locates files named pwd on the system.

locate pwd

3.)  -c option to locate, display the count of the number of matching entries.

locate -c pwd

Locate OPTIONS with Description as specified in man pages

-b, –basename
This option matches only the base name against the specified pattern on the terminal. It is the opposite of –wholename.

-c, –count
-c option writes the number of matching entries instead of writing file names on standard output.

-d, –database
-d replaces the default database with DBPATH.

An empty database file name is replaced by the default database available. A database file name – refers to the standard input.

-e, –existing
It displays only that entries which refer to files existing at a time when locate is run.


-h, –help
It displays a summary of the all available options to terminal output and then exits successfully.

-i, –ignore-case
-i ignore case distinctions when matching patterns.

-l, –limit,
It exits successfully once LIMIT entries are found.

-S, –statistics
Instead of searching for files. It writes statistics about each read database to standard output and then exits successfully.

Interpret all PATTERNs as extended regexps.

-V, –version
-V option write information about the license and version of locate on the terminal and then exits successfully.

-w, –wholename
-w matches only the whole path name with the specified pattern.

This behavior is the default. The opposite of it can be specified using –basename.

Related commands

find — Find files within a directory hierarchy.
which – shows the full path of (shell) commands.
whereis — locate the source, binary, and manual page files (man) for a command.

Add Comment