mlocate
Quick Reference
Command Name:
mlocate
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
mlocate [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 |
-n, --limit N | Same as -l |
-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 |
-q, --quiet | Write no messages about errors encountered |
-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 mlocate
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
mlocate document.pdf
Find all paths containing "document.pdf" in their name.
mlocate -i report
Find all files with "report" in their name, ignoring case (finds Report, REPORT, report, etc.).
mlocate "*.jpg"
Find all JPG images on the system.
Advanced Examples:
mlocate -c "*.pdf"
Count the number of PDF files in the database instead of displaying them.
mlocate -l 5 "*.conf"
Limit the output to just 5 config files.
mlocate -r "^/etc/.*\.conf$"
Use a regular expression to find configuration files in the /etc directory.