Easily Search Any File in Linux with the Find Command

The Linux “find” command is one of the most important and very useful commands in Linux systems. It can be used to find and locate lists of files and directories based on conditions you specify for files that match the arguments. You can find files by permissions, users, groups, file type, date, size and other possible criteria using the find command. The find command is available on most Linux distro by default, so you do not have to install a package for it.

In this tutorial we will show you how to use most used find command examples in Linux.

The most obvious way of searching for files is by name. To find a file by name in the current directory, run:

find . -name filename.txt

If you want to find a file by name that contains both capital and small letters, run:

find . -iname filename.txt

If you want to find files under a specific directory like “/home,” run:

find /home -name filename.txt

If you want to find files with the “.txt” extension under the “/home” directory, run:

find /home -name *.txt

To find files whose name is “test.txt” under multiple directories like “/home” and “/opt,” run:

find /home /opt -name test.txt

To find hidden files in the “/home” directory, run:

find /home -name ".*"

To find a single file called “test.txt” and remove it, run:

find /home -type f -name test.txt -exec rm -f {} \

To find all empty files under the “/opt” directory, run:

find /opt -type f -empty

If you want to find all directories whose name is testdir under the “/home” directory, run:

find /home -type d -name testdir

To file all empty directories under “/home,” run:

find /home -type d -empty

The find command can be used to find files with a specific permission using the perm option.

To find all files whose permissions are “777” in the “/home” directory, run:

find /home -type f -perm 0777 -print

To find all the files without permission “777,” run:

find . -type f ! -perm 777

To find all read only files, run:

find /home -perm /u=r

To find all executable files, run:

find /home -perm /a=x

To find all the sticky bit set files whose permission are “553,” run:

find /home -perm 1553

To find all SUID set files, run:

find /home -perm /u=s

To find all files whose permissions are “777” and change their permissions to “700,” run:

find /home -type f -perm 0777 -print -exec chmod 700 {} \;

To find all the files under “/opt” which are modified twenty days earlier, run:

find /opt -mtime 20

To find all the files under “/opt” which are accessed twenty days earlier, run:

find /opt -atime 20

To find all the files under “/opt” which are modified more than thurry days earlier and less than fiffy days after:

find /opt -mtime +30 -mtime -50

To find all the files under “/opt” which are changed in the last two hours, run:

find /opt -cmin -120

To find all 10MB files under the “/home” directory, run:

find /home -size 10M

To find all the files under the “/home” directory which are greater than 10MB and less than 50MB, run:

find /home -size +10M -size -50M

To find all “.mp4” files under the “/home” directory with more than 10MB and delete them using a single command, run:

find /home -type f -name *.mp4 -size +10M -exec rm {} \;

The find command is one of the most useful commands on the Linux terminal for every system administrator, as it allows the easy searching of files. If you have any questions, leave a comment below.

Leave a Reply

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.