locate
Quick Reference
Command Name:
locate
Category:
file management
Platform:
linux
Basic Usage:
Common Use Cases
- 1
File search
Search for files and directories based on name
- 2
Quick lookup
Find files quickly without traversing the filesystem
- 3
Scripting
Use in shell scripts to search for files programmatically
- 4
File management
Locate and manage files in the filesystem
Syntax
locate [OPTION]... PATTERN...
Options
Option | Description |
---|---|
-A, --all | Display all matching entries, including those on hidden paths |
-b, --basename | Match only the basename of file paths |
-c, --count | Print only the number of found entries |
-d, --database DBPATH | Use a custom database path instead of the default |
-e, --existing | Only print entries for currently existing files |
-i, --ignore-case | Ignore case distinctions when matching patterns |
-l, --limit N | Limit output to N entries |
-m, --mmap | Ignored, for backward compatibility |
-P, --nofollow | Don't follow trailing symbolic links when checking file existence |
-0, --null | Separate output with null characters, not newlines |
-S, --statistics | Print statistics about the database |
-r, --regexp REGEXP | Search using a basic regular expression |
--regex | Patterns are extended regular expressions |
-w, --wholename | Match the whole path name (default) |
Examples
How to Use These Examples
The examples below show common ways to use the locate
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
locate filename.txt
Find all paths that contain "filename.txt" in their name.
locate -i readme
Find all files with "readme" in their name, ignoring case (finds README, Readme, readme, etc.).
locate "*.conf"
Find all configuration files that end with .conf.
Advanced Examples:
locate -c "*.jpg"
Count the number of jpg files in the database instead of displaying them.
locate -l 10 "*.mp3"
Limit the output to just 10 results when searching for mp3 files.
locate -r "\bpasswd$"
Use a regular expression to find files named exactly "passwd".