Find Command

The find command is used to search and locate the list of files and directories based on conditions you specify for files that match the arguments.

Find files in the specified directory

$ find . -name sayboy.txt
$ find /home -name sayboy.txt

Use name ignoring case lookup

$ find /home -iname sayboy.txt

Find a directory by name

$ find /home -type d -name sayboy

Find all PHP files in the directory

$ find . -type f -name "*.php"

Find files with 777 permissions

$ find . -type f -perm 0777 -print

$ find / -type f ! -perm 777
$ find / -perm 2644
$ find / -perm 551
$ find / -perm /u=s
$ find / -perm /g=s
$ find / -perm /u=r
$ find / -perm /a=x
$ find / -type f -perm 0777 -print -exec chmod 644 {} \;
$ find / -type d -perm 777 -print -exec chmod 755 {} \;

Find and delete individual files

$ find . -type f -name "rumenz.txt" -exec rm -f {} \;
$ find . -type f -name "*.txt" -exec rm -f {} \;
$ find . -type f -name "*.mp3" -exec rm -f {} \;

Find all empty files or all empty directories

$ find /tmp -type f -empty
$ find /tmp -type d -empty

$ find /tmp -type f -name ".*"

Find the 50MB file

$ find / -size 50M

$ find / -size +50M -size -100M
$ find / -type f -size +100M -exec rm -f {} \;
$ find / -type f -name *.mp3 -size +10M -exec rm {} \;
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus