40 Linux Find Command Practical Examples – Really Helped me

By | January 17, 2017

40 linux find command examples made easyFind Command is most useful command in day to day work on linux machine.Without Find command it is very difficult to find any File.we can find the files by it’s name,permissions it has,Group it belongs,File Type,Size.

Whatever we tell about any command,untill we use it with purpose ,it is difficult to understand the use of it.

So let’s go ahead check now.

Usage 1:List all files in current and sub directories

## find .
./test1.txt
./test2.txt
./test3.txt

Usage 2:Search a file in current  directory,it is case sensitive.

Means,we can get the file “testname.txt” but not “TESTNAME.TXT”

## find . -name “testname.txt”
./testname.txt

Usage 3 :Search a file in current  directory without case sensitive

Means,we can get the file “testname.txt” and also file  “TESTNAME.TXT”

## find . -Iname “testname.txt”
./testname.txt
./TESTNAME.TXT

Usage 4:Search a file in Specific directory.

Means,we can get the file “testname.txt” but not “TESTNAME.TXT”

## find /myfolder/inputfiles -name “testname.txt”
/myfolder/inputfiles/testname.txt

Usage 5:Find Modified Files in last 2 hour.

We have to add hour in minutes

## find / -mmin -120

Usage 6:Find Modified Files in 1.5 hour. (90 Minutes)

## find / -mmin -90

Usage 7:Find accessed Files in 2 hour.

## find / -amin -120

Usage 8:Find accessed Files in 1.5 hour.

## find / -amin -90

Usage 9:Find changed Files in 2 hour.

## find / -cmin -120

Usage 10:Find changed Files in 1.5 hour.

## find / -cmin -90

Usage 11:Find last modified Files 100 days back.

## find / -atime 100

Usage 12:Find last modified Files 200 days back.

## find / -atime 200

Usage 13:Find last accessed Files 200 days back.

## find / -atime 100

Usage 14:Find last accessed Files 200 days back.

## find / -atime 200

Usage 15:Find last modified Files between 100-200 days back

## find / -mtime +100 -mtime  -200

Usage 16:Find last accessed Files 200 days back.

## find / -mtime +100  -mtime  -200

Usage 17:Find Files with 50MB in size from root directory.

## find / -size 50M

Usage 18:Find Files with 50 MB in the specific location.

## find /mylocation -size 50M

Usage 19:Find Files with 1 GB in the specific location.

## find / -size 1024M

Usage 20:Find Files with 1 GB in the specific location and delete them.

Be careful,before you run this query.Because it will delete the files completely.

## find / -size 1024M -exec rm -rf {} \;

Usage 21:Find Files all specific media files and delete them.

Here,i am trying to see any media file with vlc extension with more than 200 mb and applying delete on them.Scenarios,where we end up no space on our local lab machine.i know,we maintain lot of media stuff on disks 🙂

## find / -type f -name *.vlc -size +200M -exec rm {} \;

Usage 22:Find files with minimum 1 gb and maximum 10 gb in size.

With this option,we may find the all the bigger files in machine.in General we dont have any files in the size of 10 gb.(10240MB)

## find / -size +1024M -size -10240M

Usage 23:Find Largest Files in the directory.

Let’s say your disk memory is eating faster by some program.so you need to find out the files immediatly other wise.it is going to effect other programs.

It will list the top 10 Files with bigger size.

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

Usage 24:Find Empty Files in the given directory.

## find /tmp -type f -empty

Here “ f ” means Files.

Usage 25:Find Empty Directories in the given directory.

## find /tmp -type d -empty

Here d means directories.

Usage 26:Find particular files of user.

Say we have user called “JamesBond”.Let’s find out the files he own in the  server.

## find / -user JamesBond -iname *

Usage 27:Find All the Files based on the group.

## find / -group Testing

With the above command ,i will be able to find out the all the files owned by Group called Testing.

Usage 28:Find all hidden files

Most interesting part of the find usage. 🙂

## Find  /  -type f -name *

Usage 29:find and remove single file.

## find . -type f -name "myjunkfile.txt" -exec rm -f {} \;

Usage 30:Find Files with 777 Permissions and Chmod to 644

Sometimes,we are not allowed to give full permissions to all the users on files.so, we can change it by following command.

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

Usage 31:Find Files with 777 Permissions and Chmod to 644

Sometimes,we are not allowed to give full permissions to all the users on directories.so we can change it by following command.

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

Usage 32: Find only Executable Files

Search all the executables files with the below command.

## find / -perm /a=x

Search all the Read only with the below command.

Usage 33: Find Only Read Only files.

## find / -perm /u=r

Usage 34:How to run the last executed find command.

## !find

It will execute the last find command we executed

Usage 35:How to print the files in the subdirectories between level 1 and 2.

## find -mindepth 2 -maxdepth 3 -name "sum.java"

Usage 36: Finding socket files.

## find . -type s

Usage 37: Finding hidden directories

## find -type d -name ".*"

Usage 38:find files with two or multiple extensions

## find . -type f \( -name "*exe" -o -name "*xml" -o -name "*html" \)

It finds files with exe or xml or html extensions.

Usage 39 :How To Find And Execute A Command Against A File.

## find / -name filename -exec  nano '{}' \;

Usage 40:How To Send Output From Find The Find Command To A File

Some times,output from the find command is more than the screen size.To save the output from the find command and write into file,use the below command.

## find / -name *.mp3 -fprint nameoftheoutputfile
The following two tabs change content below.

SRINIVAS DARIPELLI

Myself SRINIVAS DARIPELLI. I have 15+ Years of Experience in Programming worked on multiple technologies.Apart from it,I am a blogger, writer, editor, artist and dad 🙂 .I believe in reality.I love to share the Helpful things around the Technology. Feel free to connect with me

Leave a Reply