LinuxCommandLibrary

updatedb

Update the locate command database

TLDR

Refresh database content

$ sudo updatedb
copy

Display file names as soon as they are found
$ sudo updatedb [[-v|--verbose]]
copy

SYNOPSIS

updatedb [options]

PARAMETERS

-v, --verbose
    Verbose mode; displays more information during database creation.

-o , --output=
    Specifies the output database file.

-l , --levels=
    Specifies the maximum depth to traverse in the file system. 0 for no limit. Deprecated.

-f , --filesystem=
    Limits the scan to a specific file system.

-n , --renice=
    Runs updatedb with the specified niceness value (priority). Using a higher niceness value makes it less resource-intensive.

-U , --database=
    Updates the database for a specific directory instead of the entire file system.

-h, --help
    Displays help information.

-V, --version
    Displays version information.

--prunepaths=
    Specifies a list of paths to exclude from the database, separated by colons (:).

--prunesystems=
    Specifies a list of filesystem types to exclude from the database, separated by colons (:).

--prunenames=
    Specifies a list of filenames to exclude from the database, separated by colons (:).

--require-visibility
    Only index files that are visible according to permissions.

DESCRIPTION

The updatedb command creates or updates the locate database, which is used by the locate command to quickly find files on the system. It scans the file system and builds a database of file and directory names. This database allows locate to perform searches much faster than directly traversing the file system.

updatedb is typically run as a scheduled task (e.g., via cron or systemd timers) to keep the database up-to-date. The frequency of these updates depends on how frequently files are created, modified, or deleted on the system. Running updatedb requires root privileges to access all parts of the file system (unless configured otherwise with local filesystem configurations). The database's location is usually /var/lib/mlocate/mlocate.db, but this can vary based on the system and configuration.

CAVEATS

The locate command and its database might not reflect the very latest changes to the file system until updatedb is run again. Also, if updatedb has not been run yet, the locate command will not produce any results. Permissions matter! A standard user will only see files that the user has permission to read, although updatedb itself needs superuser privilege.

CONFIGURATION

The behavior of updatedb can be configured using the /etc/updatedb.conf file. This file allows specifying which paths to exclude from the database, as well as other parameters like filesystem types to ignore. Check the file to customize the generation database according to your needs.

HISTORY

The updatedb command has been part of Unix-like operating systems for a long time. Initially, it was a simple script. Later implementations, like mlocate, improved performance and security.

Over time, the need for faster and more secure file indexing led to optimizations in how the database is created and accessed. Now is mostly implemented via `mlocate`.

SEE ALSO

locate(1), find(1), grep(1)

Copied to clipboard