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] patternPractical 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
grepSearches for patterns (text or regex) inside files and prints matching lines.
whichShows the full path of the executable that would run for a given command.
findSearches for files and directories in a directory hierarchy by name, type, size, etc.
whereisLocates the binary, source, and manual page files for a command.
xargsBuilds and executes command lines from standard input (useful with pipes).
typeDisplays how a command name would be interpreted (alias, builtin, external, etc.).