Example of linux find command

Example of linux find command

Find Command is one of the most important and frequently used command command-line utility in Unix-like operating systems. 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 can be used in a variety of conditions like you can find files by permissionsusersgroupsfile typedatesize, and other possible criteria.

Find all the files under /home directory with name eduguru.txt.

# find /home -name eduguru.txt

/home/eduguru.txt
Find all the files whose name is eduguru.txt and contains both capital and small letters in /home directory.

# find /home -iname eduguru.txt

./eduguru.txt
./Eduguru.txt

Find all directories whose name is Eduguru in / directory.

# find / -type d -name Eduguru

/Eduguru

Find all php files whose name is eduguru.php in a current working directory.

# find . -type f -name eduguru.php

./eduguru.php

Find all php files in a directory.

# find . -type f -name “*.php”

./eduguru.php
./login.php
./index.php

Find all the files whose permissions are 777.

# find . -type f -perm 0777 -print

Find all the files without permission 777.

# find / -type f ! -perm 777

To find all empty files under certain path.

# find /tmp -type f -empty

To file all empty directories under certain path.

# find /tmp -type d -empty

To find and remove multiple files such as .mp3 or .txt, then use.

# find . -type f -name “*.txt” -exec rm -f {} \;

OR

# find . -type f -name “*.mp3” -exec rm -f {} \;
To find all the files which are modified 50 days back.

# find / -mtime 50
To find all the files which are accessed 50 days back.

# find / -atime 50

To 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 changed in last 1 hour.

# find / -cmin -60

To find all the files which are modified in last 1 hour.

# find / -mmin -60

To find all the files which are accessed in last 1 hour.

# find / -amin -60

To find all 50MB files, use.

# find / -size 50M

To find all the files which are greater than 50MB and less than 100MB.

# find / -size +50M -size -100M

To find all 100MB files and delete them using one single command.

# find / -type f -size +100M -exec rm -f {} \;