locate
Quick Reference
Command Name:
locate
Category:
file management
Platform:
linux
Basic Usage:
Common Use Cases
- 1
Fast file searching
Find files anywhere on the system by name without scanning the filesystem in real-time
- 2
Pattern matching
Search for files using wildcards, regular expressions, or partial names
- 3
System exploration
Quickly discover where programs, libraries, or configuration files are installed
- 4
Filename verification
Check if certain files exist on the system and where they are located
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".