If you're using Linux, sooner or later you'll need to find a file in Linux that’s buried somewhere in your system. It could be a config file, a document, or a script you downloaded a while ago and forgot where it went. Whatever it is, there are simple ways to track it down using the terminal.
Linux is super organized but also huge. Directories like /etc
, /var
, /usr
and /home
can have tons of subfolders. Manually clicking through everything would take forever. So instead, you can search for files using their names or parts of their names. Let’s see how.
The find command
The find
command is the most flexible way to search for a file in Linux. Here’s the basic syntax:
find [starting directory] -name "filename"
For example, if you want to find a file in Linux called notes.txt
, you can run:
find / -name "notes.txt"
This searches the whole system from the root /
. It might take a while, but it works. If you want to search only your home directory (which is faster), do:
find ~ -name "notes.txt"
🔍 Use
~
as a shortcut for your home folder.
Case-insensitive search
Let’s say you’re not sure if it was saved as Notes.txt
, notes.TXT
, or NOTES.txt
. You can use -iname
for a case-insensitive search:
find / -iname "notes.txt"
Search for directories, not just files
If you’re trying to find a file but it turns out you actually need a folder (like a project directory), add -type d
:
find / -type d -name "myproject"
Want only files? Use -type f
instead.
Using locate for faster results
The find
command is powerful but can be slow because it checks every folder live. If speed matters and you just want to find file in linux fast, locate
is the tool for you. First, install it if needed:
sudo apt install mlocate sudo updatedb
Now you can just type:
locate notes.txt
It shows results instantly because it uses a pre-built database.
Searching with wildcards
What if you don’t remember the full name? Wildcards help a lot.
find / -name "*.log"
This finds all files that end in .log
.
Or if you remember part of the name:
find / -name "*report*"
This finds anything with "report" in the name, like sales_report.pdf
or report_final.docx
.