Skip to main content

What is Locate?

locate finds files by querying a pre-built database instead of reading the live filesystem. This makes it nearly instantaneous for any query.

Mental model: locate is like a search engine for your disk. updatedb is the web crawler that builds the index. locate is the query interface.

Nightly job: updatedb → scans filesystem → writes /var/lib/mlocate/mlocate.db

Your query: locate nginx.conf → reads database → returns results instantly

The Database Trade-Off

Propertylocatefind
SpeedInstant (ms)Seconds to minutes
Data freshnessStale (up to 24h)100% real-time
Metadata filtersNone (path only)Full (size, perms, time)
New files since last updatedb❌ Not found✅ Found
Deleted files since last updatedb❌ Still listed✅ Gone

Variants: mlocate vs plocate

VariantNotes
mlocateMost common on Ubuntu/Debian. Merged database, security-aware
plocateNewer, faster. Uses compressed trigram index. Replaces mlocate on Ubuntu 22.04+
slocateLegacy. Used SUID bit for per-user results. Largely deprecated

On modern Ubuntu, locate is typically a symlink to plocate or mlocate.

ls -la $(which locate)
# /usr/bin/locate -> /usr/bin/plocate

Security Model

mlocate runs updatedb as root, but indexes only files that are readable by root. When a regular user queries locate, it checks their permissions before showing results. Users cannot see files they don't have permission to access.