updatedb
Update the locate command database
TLDR
Refresh database content
Display file names as soon as they are found
SYNOPSIS
updatedb [OPTION]...
PARAMETERS
-o, --output FILE
Specifies the path for the output database file, overriding the default location.
-c, --config-file FILE
Uses a custom configuration file instead of the default /etc/updatedb.conf.
-v, --verbose
Enables verbose output, displaying detailed information about the scanning process.
--help
Displays a help message and exits.
--version
Displays version information and exits.
DESCRIPTION
The updatedb command is a crucial utility in Linux systems responsible for creating or updating the file index database used by the locate command. Unlike find, which scans the filesystem in real-time, locate queries this pre-built database for extremely fast file searches. updatedb typically runs as a scheduled cron job, often daily, to ensure the database remains reasonably current with filesystem changes.
When executed, updatedb recursively scans the specified filesystems (or the entire root filesystem by default) and records the names and paths of all accessible files. Its behavior is primarily controlled by a configuration file, usually /etc/updatedb.conf, which defines parameters such as filesystems to exclude (PRUNEFS), paths to prune (PRUNEPATHS), and whether to prune bind mounts (PRUNE_BIND_MOUNTS). To effectively scan the entire system and collect comprehensive file information, updatedb usually requires root privileges. The generated database is typically stored at /var/lib/mlocate/mlocate.db for the mlocate implementation.
CAVEATS
Updatedb creates a snapshot of the filesystem, meaning it does not reflect real-time changes; newly created or deleted files will only appear/disappear after the next database update.
Running updatedb can be resource-intensive, consuming CPU and disk I/O, especially on large filesystems. It typically requires root privileges to ensure a complete scan of the entire system. The database, while efficient for searching, contains paths to all files, which might be a security consideration if not properly secured, although it's usually world-readable.
CONFIGURATION
The behavior of updatedb is largely controlled by its configuration file, typically located at /etc/updatedb.conf. Key variables in this file include:
PRUNEFS: A space-separated list of filesystem types to exclude from the scan (e.g., `proc`, `sysfs`, `tmpfs`).
PRUNEPATHS: A space-separated list of paths to exclude (e.g., `/tmp`, `/var/tmp`, `/mnt`).
PRUNE_BIND_MOUNTS: A boolean (0 or 1) indicating whether to prune bind mounts.
These settings prevent updatedb from indexing irrelevant or volatile parts of the filesystem, saving space and improving performance.
DATABASE LOCATION
The default location for the generated locate database is commonly /var/lib/mlocate/mlocate.db for systems using mlocate. This file is then queried by the locate command to perform fast searches.
SCHEDULING
updatedb is almost always run automatically via a system cron job. On many distributions, there's a daily cron script (e.g., in /etc/cron.daily/ or /etc/cron.weekly/) that executes updatedb to keep the file database current without requiring manual intervention.
HISTORY
The updatedb utility has been a core component of Unix-like systems for decades, originally part of the findutils package. Its primary purpose was to build an index for the locate command, enabling rapid file searches. Over time, more advanced and secure implementations emerged, notably slocate (secure locate) and later mlocate (merging features of both).
mlocate has become the standard locate and updatedb implementation on most modern Linux distributions. It introduced features like ignoring files that users are not allowed to see, making the locate command's output more secure and consistent with user permissions. The development of mlocate focused on improving efficiency and security over its predecessors, making the updatedb process faster and the database more reliable.