Linux find Command with 20 Examples
Linux finds a command-line utility used to search files and directories based on different permissions, ownership, modification, etc. In this article, we will cover Linux find Command with 20 Examples.
Linux find command is available in all Linux-based distro, hence no need to install it separately. This powerful command helps you to locate resources in your system.
Syntax
Below is the generic syntax of find command:
find <path> <option> <crtieria>
(1) Find files using filename in current directory
find . -name <file-name>
(2) Search for file in specific directory
find <directory-path> -name <file-name>
(3) Find files using filename ignoring case
find . -iname <filename>
(4) Search for pattern in file in specific directory
find <directory-path> -name *.<extension-name>
(5) If you interested to see manual of find command
find --
help
(6) Search empty directory and file
find <directory-path> -empty
(7) Search for file with specific permissions
find <directory-path> -perm <nnn>
(8) Search directories using name in current directory
find / -type d -name <directory-name>
(9) Search SGID Files with specific permissions
find / -perm 2604
(10) Search all SGID set files
find / -perm /g=s
(11) Search read only files in current directory
find . -perm /u=r
(12) Search executable files
find / -perm /a=x
(13) Search files with specific permissions and change permissions.
find / -type f -perm 0744 -print -exec chmod 644 {} \;
(14) Search directory with specific permissions and change permissions
find / -type d -perm 744 -print -exec chmod 744 {} \;
(15) Search all hidden files in usr directory
find /usr -type f -name ".*"
(16) Search all files filter by username
find /home -user <user-name>
(17) Search all files based on group
find /home -group <group-name>
(18) To search all the files which are modified 40 days back
find / -mtime 40
(19) Search accessed files in last 40 days
find / -atime 50
(20) Search modified files in range of 20 to 50 days
find / -mtime +20 –mtime -50
Conclusion
Linux find command is a powerful command only if you use or exploit it with full potential. In this article, we have discussed a brief about Linux find command and mentioned 20 examples of how we can use it effectively.
Subscribe us to receive more such articles updates in your email.
If you have any questions, feel free to ask in the comments section below. Nothing gives me greater joy than helping my readers!
Disclaimer: This tutorial is for educational purpose only. Individual is solely responsible for any illegal act.