find - search for files in a directory hierarchy.
find . -name file.txt
./file.txt
find
command.
means it will search all the directory you are in and sub directories.-name
will look for that name exactly, if a character is different or upper or lower case, it will ignore it.file.txt
filenamefind /home/ -iname file.txt
./file.txt
./File.txt
find / -type -d -name Photos file.txt
/home/user/Photos
find /home/ -name *ile*
./home/file.txt
./home/File.txt
./home/My_Files-NEWS.txt
./home/file.sh
find / -type -f -name Photos *.odt
./file.odt
./terminalroot.odt
-f
only files with extension odt
, in that case, even without -f
would also find
777
find . -type f -perm 0777 -print
777
find / -type f ! -perm 777
- type d
or - type f
it searches bothfind MyDir/ -empty
MyDir/EmptyDir
MyDir/EmptyFile.txt
-type d
search only directoriesfind MyDir/ -type d -empty
MyDir/EmptyDir
-type f
looks for files onlyfind MyDir/ -type f -empty
MyDir/EmptyFile.txt
find /tmp -type f -name ".*"
find . -type f -size +10M
You will find all files smaller than 10MB
find. -type f -size -10M
-exec
find . -type f -name EmptyFile.txt -exec rm -f {} \;
Or with xargs
find . -type f -name EmptyFile.txt | xargs rm -f
find My_Files/ -name "*.*" -exec grep -Hin "Anomalies" {} \;
My_Files/file.txt:1:Anomalies
atime
) files in the last 24 hours (for more than 3 days, use +3)find . -type f -atime -1 -exec ls -l {} \;
amin
) files in last 5 minutesfind . -type f -amin -5
ctime
) files in the last 12 hoursfind . -type f -ctime -0.5 -exec ls -l {} \;
mtime
) files in the last 6 hoursfind . -type f -mtime -0.25
551
Permissionfind / -perm 1551
find / -perm /u=s
find / -perm /g+s
find / -perm /a=x
or read only
find / -perm /u=r
There are more possibilities, you can see them all in the command manual:
man find
find --help
Thanks for reading!