Locate Documentation
A comprehensive guide to locate — the fastest file-finding utility on Linux. Unlike find, which reads the live filesystem, locate queries a pre-built database and returns results in milliseconds.
Mental model:
locateis a search engine for your filesystem. The database is the index,updatedbis the crawler, andlocateis the query interface.
Where locate Fits
| Tool | Speed | Accuracy | Filters |
|---|---|---|---|
find | Medium | 100% real-time | Metadata (size, perms, time) |
locate | Instant | Stale by up to 24h | Path substring only |
fd | Fast | 100% real-time | Name, type, time, size |
Use locate when: you want instant results and don't care about files created in the last 24 hours.
Curriculum
1. Introduction
- What is Locate? — Architecture, mlocate vs plocate.
- Locate vs Find vs fd — When to use which.
2. Installation & Setup
- Installing locate — mlocate, plocate, and the updatedb cron job.
3. Core Searching
- Basic Patterns — Substring, case sensitivity, and limits.
- Regex and Basename —
--regex,-b, and anchoring.
4. Database Management
- Updatedb — Manual updates, cron scheduling, and database location.
- Excluding Paths —
/etc/updatedb.confconfiguration.
5. Advanced Filtering
- Existence Checks —
-eto filter stale results. - Counting and Stats —
-cand database size information.
6. Scripting & Pipelines
- Safe Output — Null-delimited output and xargs.
- Pipeline Workflows — Combining with grep, sort, and wc.
7. Real World Workflows
- Config File Discovery — Finding config files system-wide.
- Quick Sysadmin Lookups — Man pages, libraries, and binary paths.
8. Troubleshooting
- Stale Results — Ghost files and missing entries.
- Permission Issues — SLOCATE and database access.
9. Cheatsheet
- Locate Cheatsheet — All flags and recipes.
Quick Start
# Install and initialize
sudo apt install mlocate && sudo updatedb
# Search instantly
locate nginx.conf # find by substring
locate -i "readme" # case insensitive
locate -b "\nginx.conf" # basename exact match
locate -e "*.log" | head -20 # only show files that exist