How to use locate for fast file finding
· Category: Linux
Short answer
locate searches a prebuilt database of filenames for near-instant results.
Steps
- Update the database:
sudo updatedb
- Find a file:
locate myfile.txt
- Case-insensitive search:
locate -i myfile
- Limit results:
locate -n 10 myfile
Tips
locateis faster thanfindfor simple name searches.- The database is updated periodically by cron; run
updatedbmanually for recent files. - Use
mlocatefor secure indexing that respects permissions.
Common issues
- New files not found: the database may be stale.
- Too many results: narrow the pattern or pipe to
grep.