← ../

find

a very powerful command to let you search for files with different filter and run command(s) on the matching files.

some useful switches below :

find all the files in /home with name test.txt

find /home –name test.txt

find all the files in /home with name test.txt (case insensitive)

find /home –iname test.txt

search for only directories whose name is var in / directory

find / -type d –name var

search for files which are more than 1GB size in /usr folder

find /usr –size +1G

search for files which are of type file with permissions 664

find / -type f -perm 664

search for files that belongs to user toto

find / -user toto

find all the files which are modified more than 90 days back and less than 180 days (you can also filter down to minutes with the -mmin flag)

find / -mtime +90 –mtime -180

remove all files in your Music home directory that ends with ".mp3"

see also the variant that pipes the output to the xargs command (see xargs man page for more info)

# note : the braces are enclosed in single quote marks to protect them from interpretation as shell script punctuation
# note : the semicolon is simi-larly protected by the use of a backslash
find ~/Music/ -iname "*.mp3" -exec rm '{}' \;
or
find ~/Music/ -iname "*.mp3" -print0 | xargs -0 /bin/rm