mlocate
Find files quickly by name
SYNOPSIS
mlocate [OPTIONS] PATTERN...
PARAMETERS
-b, --basename
Match only the base name of the path, not the full path.
-c, --case-sensitive
Perform a case-sensitive search. This overrides the default case-insensitive behavior.
-d, --database PATH
Specify an alternative database file to search instead of the default /var/lib/mlocate/mlocate.db.
-e, --existing
Only print entries that existed at the time mlocate was run. This checks the filesystem for actual file existence.
-i, --ignore-case
Perform a case-insensitive search. This is the default behavior.
-L, --local-filesystem
Limit the search to filesystems that were considered local during the updatedb run. This excludes network filesystems.
-l, --limit NUM
Limit the number of search results to NUM.
-P, --nofollow
Do not follow symbolic links when determining file paths (relevant to how updatedb built the database).
-r, --regexp
Interpret the PATTERN as a basic regular expression (BRE).
-q, --quiet
Suppress any error messages.
-S, --statistics
Print statistics about the database, such as the number of files and directories.
-s, --stdio
Print results to standard output, one path per line.
-U, --filesystem FS
Restrict the search to specific filesystems that were included in the database by updatedb.
-V, --version
Display version information and exit.
-w, --wholename
Match the entire path name, not just the base name. This is the default behavior.
--help
Display a help message and exit.
DESCRIPTION
The mlocate command is a powerful utility for quickly locating files and directories on a Linux system. Unlike the find command, which traverses the live filesystem, mlocate performs searches against a pre-built database, typically located at /var/lib/mlocate/mlocate.db. This database is generated and regularly updated by the updatedb command, usually through a daily cron job.
Because it relies on a database, mlocate delivers results almost instantaneously, making it exceptionally fast for common searches. However, this also means its results are only as current as the last database update. Files created or deleted since the last updatedb run will not be accurately reflected.
mlocate also incorporates security features: the database only contains paths visible to the user who ran updatedb (typically root), and when a regular user runs mlocate, it filters the results to show only files they currently have permission to access.
CAVEATS
The primary limitation of mlocate is that its database is not real-time. Results may be outdated, failing to show newly created files or showing files that have since been deleted.
While mlocate filters results based on current user permissions, the database itself contains all entries visible to the user who ran updatedb (usually root). This means that potentially sensitive filenames might be present in the database, even if a user cannot access the file content.
DATABASE LOCATION
The default database file for mlocate is typically located at /var/lib/mlocate/mlocate.db. This file is usually owned by root and has restricted permissions.
DATABASE UPDATES
The mlocate database is not updated automatically in real-time. It relies on the updatedb command to scan the filesystem and rebuild the database. On most systems, updatedb is configured to run daily via a cron job, ensuring the database remains reasonably current.
HISTORY
mlocate, short for 'merging locate', was developed as a modern and more secure successor to the traditional locate command. Older locate implementations often had security vulnerabilities related to how they handled permissions and paths. mlocate was designed to address these issues by using a more robust database format and by filtering results based on the current user's permissions at runtime. It also often provides better performance for very large filesystems compared to its predecessors.