Installing locate
Ubuntu / Debian (mlocate)
sudo apt update
sudo apt install mlocate
# Build the initial database (required before first use)
sudo updatedb
# Verify
locate locate
Ubuntu 22.04+ (plocate)
Ubuntu 22.04 ships plocate as the default. It is faster and uses less disk space:
sudo apt install plocate
sudo updatedb # same command, plocate's updatedb
locate --version
Fedora / RHEL
sudo dnf install mlocate
sudo updatedb
Alpine Linux
apk add mlocate
updatedb
The Automatic Cron Job
After installation, a cron job is automatically added to run updatedb daily (usually between 00:00 and 06:00):
# View the scheduled job
cat /etc/cron.daily/mlocate
# (or /etc/cron.daily/plocate)
The cron job runs as root and rebuilds the entire database. Frequency depends on how frequently your system's file layout changes.
Running updatedb Manually
After installing new software, creating important directories, or before searching for something you just created:
sudo updatedb
On a typical server with hundreds of thousands of files, updatedb takes 5–30 seconds.
Database Location
# mlocate database
ls -lh /var/lib/mlocate/mlocate.db
# plocate database
ls -lh /var/lib/plocate/plocate.db