Find Command


Find Command – AyeSir.org


Find command is used to find files and directories and sub directories in UNIX

Examples of find command

Find file with name filename.txt in current directory

find . -name filename.txt

Find file filename.txt in /abc directory

find /abc -name filename.txt

Find all files with name aks.txt with both block letter and small letters in /abc directory.

find /abcd -iname aks.txt

./aks.txt

./AKS.txt

./Aks.txt

Find all directories /xyz in /abc directory

find / type d -name xyz

/xyz

Find all log file in current directory with name today.log

find . type f -name today.log

./today.log

Find all csv files in current directory

find . -type f -name “*.log”

Find files with file permission 755 in current directory

find . -type f -perm 755 -print

Find files with 755 permissions and change it to 700

find / -type d -perm 755 -print -exec chmod 700 {} \;

Find directories with 644 permissions and change it to 600

find / -type  d -perm 644 -print -exec chmod 600 {} \;

Find all empty files

find /tmp -type f -empty



Find all empty directories

find /tmp -type d -empty

Find all files created by a user “amit”

find . -user amit

Find all hidden files in current directories

find . -type f -name “.*”

Find file modified in last 30 days

find .  -mtime 30

Find all files accessed 20 days back

find . -atime 20

Find all files accessed in last 1hr

find . -amin -60

Find all files which are modified between last 10-20 days

find . -mtime +10 -mtime -20

Find all files which are changed in last 1 hr

find . -cmin -60



Find all files which are modified in last 40 minutes

find . -mmin -40

Find all files of 10 MB

find . -size 10M

Find all files between 10 to 15 MB

find . -size +10M  – size -20M

Find 30 MB file and delete

find . -size +30M -exec rm -rf {} \;

Find all files modified in exact 1 day

find . -mtime 1

Find all files modified in more than 1 day

find . -mtime +1

Find all files modified in less than 1 day

find . -mtime -1

Find files only in current directory and not in sub directory

find -maxdepth 1 -type f -name filename.txt




Find files in current directory and one level down in sub directories

find -maxdepth 2 -type f -name filename.txt

Find files containing specific words in its name

find . -name “*aks*”

./aks.txt

./aks.log

./raks.csv

Find files with not containing specific filename

find . -not -name  “*aks*”

Find files in sub directories between level 3 to level 5

find . -mindepth  4 -maxdepth 6 -name “aks.txt”

Find largest files in current directory and sub directories

find . -type f -exec ls -s {} \; | sort -n -r | head -1

Find smallest files in current directory and sub directories

find . -type f -exec ls -s {} \; | sort -n -r | tail -1

Find files which are accessed after modification to file aks.txt

find -anewer “aks.txt”

Find files which are modified after modification of file aks.txt

find -newer “aks.txt”