Skip to main content

Locate vs Find vs fd

Decision Matrix

ScenarioBest ToolReason
"Where is php.ini?"locateKnown file, existing, speed matters
"Delete logs older than 30d"findTime metadata required
"Find files containing 'TODO'"rg / grepContent search, not file discovery
"Find files in a Git repo"fdgitignore-aware, fast
"Audit SUID binaries"findPermission metadata required
"Quick 'does this file exist?'"locate -cInstant 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