The Linux find command is one of the most important and commonly used command line applications in Unix-like operating systems. The find command is used to search for and locate files and directories that match the specified parameters. The find command provides a variety of options that users can use under different conditions. You can search for files based on different criteria, such as permissions, users, groups, file type, date, size, and other parameters.
To find a file with a specific name, find all files named tecmint.txt in your current working directory:
# find . -name tecmint.txt
./tecmint.txt
Find all the files named tecmint.txt in the /home directory.
# find /home -name tecmint.txt
/home/tecmint.txt
Look in the /home directory for all files named tecmint.txt that contain upper and lower case letters.
# find /home -iname tecmint.txt
./tecmint.txt
./Tecmint.txt
Find all directories named Tecmint in the/directory.
# find / -type d -name Tecmint
/Tecmint
Find all the php files named tecmint.php.
# find . -type f -name tecmint.php
./tecmint.php
Find all php files in the directory.
# find . -type f -name "*.php"
./tecmint.php
./login.php
./index.php
Find all files with permission 666.
# find . -type f -perm 0666 -print
Find all 666 files without permissions:
# find / -type f ! -perm 777
Finds all SGID bit files with permission set to 644.
# find / -perm 2644
To find a Sticky Bit file with 551 permissions:
# find / -perm 1551
Find all SUID Settings files.
# find / -perm /u=s
Finds all SGID set files.
# find / -perm /g=s
Find read-only files:
# find / -perm /u=r
Find all executable files:
# find / -perm /a=x
Find all 666 permission files and use the chmod command to set the permission to 644.
# find / -type f -perm 0666 -print -exec chmod 644 {} \;
Find all 666 permissions directories and use the chmod command to set permissions to 755.
# find / -type d -perm 666 -print -exec chmod 755 {} \;
Find a file named tecmint.txt and delete it.
# find . -type f -name "tecmint.txt" -exec rm -f {} \;
To find and delete multiple files (such as.mp3 or.txt), use.
# find . -type f -name "*.txt" -exec rm -f {} \;
OR
# find . -type f -name "*.mp3" -exec rm -f {} \;
Find all empty files in a path:
# find /tmp -type f -empty
Archive all empty directories in a path.
# find /tmp -type d -empty
To find all hidden files, use the following command.
# find /tmp -type f -name ".*"