How to Find a File by Name on Linux from the Terminal
With find and locate, and when to use each one.
find / -iname "*report*" 2>/dev/null
-iname searches case-insensitively (more flexible than
-name). The 2>/dev/null hides "permission
denied" warnings on system folders you don't have access to, leaving
only useful results.
Faster for everyday use: locate
sudo apt install mlocate
sudo updatedb
locate report
locate is much faster than find because
it queries an already-built index, instead of scanning the disk at
that moment — but for that same reason it won't find files created
after the last time that index was updated (with
updatedb, which runs automatically every day).
Tip: use find if you need instantly
guaranteed results (including files created a minute ago); use
locate for quick everyday searches where it doesn't
matter if the index is a few hours old.
Frequently asked questions
Why doesn't locate find a file I just created?
Because locate queries an index that updates periodically (usually once a day), not in real time. Run 'sudo updatedb' manually to force an immediate update.
Why does find show so many 'permission denied' errors?
Because it tries to search system folders your user doesn't have access to. Adding '2>/dev/null' at the end of the command hides those warnings, leaving only the useful results.