Locate vs Find vs fd
Decision Matrix
| Scenario | Best Tool | Reason |
|---|---|---|
| "Where is php.ini?" | locate | Known file, existing, speed matters |
| "Delete logs older than 30d" | find | Time metadata required |
| "Find files containing 'TODO'" | rg / grep | Content search, not file discovery |
| "Find files in a Git repo" | fd | gitignore-aware, fast |
| "Audit SUID binaries" | find | Permission metadata required |
| "Quick 'does this file exist?'" | locate -c | Instant count query |
When locate Is Perfect
# Find any php.ini anywhere on the system (instant)
locate php.ini
# Find all nginx config files
locate nginx.conf
# Find where a Python module is installed
locate site-packages/requests/__init__.py
# Find man page locations
locate man/man1/grep.1
# Verify a binary exists and find its path
locate /bin/ffmpeg
When locate Fails
# File created 10 minutes ago — NOT in database
touch /tmp/newfile.txt
locate newfile.txt # returns nothing!
find /tmp -name "newfile.txt" # finds it immediately
# File deleted 5 minutes ago — STILL in database
rm /etc/old.conf
locate old.conf # still listed (ghost result)
locate -e old.conf # -e checks existence → filtered out ✓
The Hybrid Approach
Use locate for discovery, then find for verification:
# 1. Instantly find candidate paths
locate "nginx.conf"
# 2. If you need to act on them, verify with find
find /etc/nginx -name "nginx.conf" -mtime -7