find Flashcards
find
GNU find searches the directory tree rooted at each given starting-point by evaluating the given expression from left to right, according to the rules of precedence until the outcome is known, at which point find moves on to the next file name.

find [OPTIONS]
- P
- L
- H
- D
- 0
- P, Never follow symbolic links.
- L, Follow symbolic links.
- H, Do not follow symbolic links, except while processing the command line arguments.
- D debugopts, Print diagnostic information.
- 0level, Enables query optimisation.
find . -name text1
Finds files with the name text 1 in the current directory.
find /home -name text1
Finds files with the name text1 in the /home directory.
find /home -iname text1
Ignores the case of text1 while trying to find matching files in /home.
find / -type d -name text1
Searches for directories from / named text1
find . -type f -name text.php
Looks for files named text.php in current directory.
find . -type f -name “*.php”
Finds all php files in current directory.
find / -type f -perm 0777 -print
Find all the files whose permissions are 777.
find / -type f ! -perm 777
Find all the files without permission 777.
find / -perm 2644
Find all the SGID bit files whose permissions set to 644.
find / -perm 1551
Find all the Sticky Bit set files whose permission are 551.
find / -perm /u=s
Find all SUID set files.
find / -perm /g=s
Find all SGID set files.
find / -perm /u=r
Find all Read Only files.
find / -perm /a=x
Find all Executable files
find / -type f -perm 0777 -print -exec chmod 644 {} \;
Find all 777 permission files and use chmod command to set permissions to 644.
find / -type d -perm 777 -print -exec chmod 755 {} \;
Find all 777 permission directories and use chmod command to set permissions to 755
find . -type f -name “tecmint.txt” -exec rm -f {} \;
To find a single file called tecmint.txt and remove it.
find . -type f -name “*.txt” -exec rm -f {} \;
OR
find . -type f -name “*.mp3” -exec rm -f {} \;
To find and remove multiple files such as .mp3 or .txt.
find /tmp -type f -empty
To find all empty files under certain path.
find /tmp -type d -empty
To file all empty directories under certain path.
find /tmp -type f -name “.*”
To find all hidden files, use below command.
find / -user root -name tecmint.txt
To find all or single file called tecmint.txt under / root directory of owner root.
find /home -user tecmint
To find all files that belongs to user Tecmint under /home directory.
find /home -group developer
To find all files that belongs to group Developer under /home directory.
find /home -user tecmint -iname “*.txt”
To find all .txt files of user Tecmint under /home directory.