find is a powerful command on Linux, it allows you to search for files and folders using different criteria: name, size, type, owner.
In this guide, you will see some useful commands for files and folders.
Search files by name in the current directory :
# find . -name document.txt
This command allows you to search for files whose name is « document.txt » (using the -name parameter) in the current directory (indicated by the dot « . »)
Search files by name in a specified directory :
# find /root -name *.log
The command finds files that end with « .log » in the / root directory.
Search for a directory by name :
# find /home -type d -name document
The command finds directories ( using the -type parameter ) whose name is « document ».
Find empty files :
# find / -type f -empty
The command displays all empty files (-empty) present in the « / » root.
Search for empty folders :
# find / -type d -empty
The command displays all empty folders (-empty) present in the « / » root.
Find hidden files:
# find /var -type f -name ".*"
The command displays all hidden files that are located in the /var directory.
Find all files owned by the root user :
# find / -user root -name log
Find all files owned by the group « training »
# find / -group formation -name log
Find files modified 25 days ago
# find / -mtime 25
Find files modified 2 hours ago :
# find / -mmin 120
Search for files whose size is 65M :
# find / -size 65M
Find files between 120M and 40M in size :
# find / -size +40M -size -120M
nmap : les 12 commandes que vous devez connaître
Le fonctionnement du routeur
Protocole du routage
Netstat : Les 14 commandes les plus utilisées
Fail2Ban : How to protect Linux services