GO KALI FREE
Search Commands

locate Linux Command

Quickly finds files by name using a pre-built database (run updatedb to refresh).

What does locate do?

Quickly finds files by name using a pre-built database (run updatedb to refresh).

Syntax

locate [options] pattern

Practical example

locate '*.conf'

Questions about locate

How do I find a file by name with locate?

Use `locate filename` to search for files by name. It searches a pre-built database, making it much faster than find.

How do I update the locate database?

Use `sudo updatedb` to refresh the locate database. This is necessary to find recently created files.

How do I search case-insensitively with locate?

Use `locate -i 'pattern'` to ignore case when searching. This matches files regardless of uppercase or lowercase.

How do I find only existing files with locate?

Use `locate -e 'pattern'` to exclude deleted files from the results. By default, locate shows files from the last database update.

How do I count files with locate?

Use `locate -c 'pattern'` to count the number of matching files without listing them.

How do I search for files in a specific directory?

Use `locate '/path/pattern'` to restrict the search to a specific directory path.

What is the difference between locate and find?

locate searches a database (fast but may be outdated). find searches the filesystem in real-time (slow but always current).

How do I install locate?

On Debian/Ubuntu: `sudo apt install mlocate`. On RHEL/CentOS: `sudo yum install mlocate`.

Related Search Commands

grep

Searches for patterns (text or regex) inside files and prints matching lines.

which

Shows the full path of the executable that would run for a given command.

find

Searches for files and directories in a directory hierarchy by name, type, size, etc.

whereis

Locates the binary, source, and manual page files for a command.

xargs

Builds and executes command lines from standard input (useful with pipes).

type

Displays how a command name would be interpreted (alias, builtin, external, etc.).