When working with a Linux system, it’s important to find the files and folders we need without manually checking each one. There are tools that can help us do this efficiently.
- which Command
The which command helps us find the exact location of a program or tool in the system. For example, if we want to check if Python is installed and where it is located, we can run:
which pythonThis will return something like:
/usr/bin/pythonIf the program is not installed, it won’t show any output.
2. find Command
The find command helps us locate files and folders based on different filters like name, size, owner, and modification date.
Basic Syntax:
find <location> <options>Example:
find / -type f -name "*.conf" -user root -size +20k -newermt 2020-03-03 -exec ls -al {} \; 2>/dev/nullWhat this does:
- type f → Look for files only (not folders).
- name “*.conf” → Find files that have .conf in their name.
- user root → Show only files owned by the root user.
- size +20k → Find files larger than 20 KB.\
- newermt 2020-03-03 → Find files modified after March 3, 2020.
- exec ls -al {} \; → Show details (like permissions and size) of each found file.
- 2>/dev/null → Hide any error messages.
3. locate Command
The locate command is a faster way to search for files because it uses a database instead of scanning the entire system. However, it may not show newly created files unless the database is updated.
Updating the database:
sudo updatedbFinding all .conf files quickly:
locate *.confOutput example:
- /etc/GeoIP.conf
- /etc/NetworkManager/NetworkManager.conf
- /etc/adduser.conf
Limitations: locate is fast but does not have advanced filters like find.
