Find
Find
List all files found in the current hierarchy, and all the hierarchy below /home/xyz
$ find. /home/XYZ
Search for a file by the name abc in the current directory and its hierarchy
$ find ./ -name abc
Search for a directory by the name xyz in the current directory and its hierarchy
Search for a file by the name abc.txt below the current directory, and prompt the user
to delete each match.
Search for files that were modified in the last 7 days below the current directory
$ find ./ -mtime -7
Search for files that have all permissions set in the current hierarchy
$ find ./ -perm 777
Find all the files whose name is tecmint.txt and contains both capital and small
letters in /home directory.
Find all php files whose name is tecmint.php in a current working directory.
# find . -type f -name tecmint.php
Find all php files in a directory.
# find . -type f -name "*.php"
Find all the Sticky Bit set files whose permission are 551.
# find / -perm 1551
Find all 777 permission files and use chmod command to set permissions
to 644.
Find all 777 permission directories and use chmod command to set
permissions to 755.
To find all or single file called tecmint.txt under / root directory of owner root.
# find / -user root -name tecmint.txt
To find all files that belongs to user Tecmint under /home directory.
# find /home -user tecmint
To find all files that belongs to group Developer under /home directory.
4
-mtime +60 means you are looking for a file modified 60 days ago.
-mtime -60 means less than 60 days.
-mtime 60 If you skip + or – it means exactly 60 days.
o find all the files which are modified more than 50 days back and less
than 100 days.
# find / -mtime +50 –mtime -100
To find all the files which are greater than 50MB and less than 100MB.
# find / -size +50M -size -100M
o find all 100MB files and delete them using one single command.
# find / -type f -size +100M -exec rm -f {} \;
Find all .mp3 files with more than 10MB and delete them using one single
command.
# find / -type f -name *.mp3 -size +10M -exec rm {} \;