How to Search for Files in Linux (find, locate, which)
Introduction
Searching for files is a common task in Linux. Depending on the situation, you can use different commands like find, locate, and which to quickly locate files and executables.
Step 1: Search with find
find /path -name filename
➡️ Example:
find /home -name "*.txt"
This searches for all .txt files inside /home.
Step 2: Search with locate
locate filename
➡️ Example:
locate passwd
This uses a prebuilt database and is much faster than find.
⚠️ Run sudo updatedb if results seem outdated.
Step 3: Search with which
which command
➡️ Example:
which python
This shows the path of the executable file used by the shell.
Step 4: Search with whereis
whereis command
➡️ Example:
whereis ls
This shows the binary, source, and man page locations.
Conclusion
Linux provides multiple ways to find files depending on speed and accuracy. find is powerful, locate is fast, and which/whereis are best for executables.

Comments
Post a Comment