LinuxCommandLibrary

mlocate

Find files quickly by name

SYNOPSIS

locate [OPTION]... PATTERN...

PARAMETERS

-a, --all
    Print all matching entries; by default, `locate` stops after finding 20 entries.

-b, --basename
    Match only the base name of pathnames.

-c, --count
    Instead of writing file names on standard output, write the number of matching entries only.

-d, --database PATH
    Search the specified database instead of the default database.

-e, --existing
    Print only entries that refer to files existing at the time locate is run.

-i, --ignore-case
    Ignore case distinctions when matching patterns.

-l, --limit NUMBER
    Limit the number of entries printed to NUMBER.

-m, --mmap
    Use memory-mapped input.

-n, --no-newline
    Do not print newlines.

-o, --output FILE
    Specify output FILE.

-P, --nofollow
    Do not follow symbolic links when checking if files exist.

-0, --null
    Separate entries with null characters instead of newlines.

-r, --regexp REGEXP
    Search using extended regular expressions (slower).

-S, --statistics
    Print statistics about the locate databases.

-V, --version
    Print version information and exit.

-w, --wholename
    Match only whole pathnames.

-h, --help
    Display help message and exit.

DESCRIPTION

mlocate is a utility for quickly locating files on a Linux system. It works by maintaining a database of file names and their locations, built by the `updatedb` command. Unlike `find`, which searches the file system in real-time, `mlocate` searches this database. This makes searches significantly faster, especially on large file systems. The database is updated periodically (typically daily), so results might not always reflect the very latest file system changes. mlocate is a modern, security-conscious reimplementation of the `locate` command. It considers file permissions during the database creation process, ensuring that users can only find files that they have permission to access. The database includes all filenames and also pathnames. The `locate` command is part of the `mlocate` package. It improves upon the original `locate` by only indexing files the user has permissions to read.

Note: `mlocate` relies on a pre-built database, it is crucial to run `updatedb` regularly (usually via a cron job or systemd timer) to keep the database current for accurate search results.

CAVEATS

The locate database is not updated in real-time. Results may not include recently created files until the database is updated (usually via cron or systemd timer). Also, due to permission-based indexing, users may not find files they do not have permission to read.

DATABASE CONFIGURATION

The behavior of `updatedb` (and therefore `locate`) can be customized through configuration files such as `/etc/updatedb.conf`. This file allows specifying which directories to include or exclude from the database, as well as other parameters like the filesystem types to scan. Make sure your system configuration is configured properly, otherwise your search will have inconsistent results.

The main parameters are PRUNEPATHS which defines which paths to skip when generating DB, and PRUNE_BIND_MOUNTS that defines if bind mounts should be skipped.

HISTORY

The `locate` command has been a staple of Unix-like operating systems for a long time. `mlocate` is a modern reimplementation designed with security in mind, addressing potential vulnerabilities in earlier versions that could allow users to discover files they shouldn't have access to. The `updatedb` command, which creates the database used by `locate`, is also a crucial part of the `mlocate` package.

SEE ALSO

find(1), updatedb(1)

Copied to clipboard