find's Examples

Search a  file with specific name

It will search for sample.txt for GFG directory

$ find. /GFG -name sample.txt

Search a file with pattern

It will give all which have .txt at the end

$ find ./GFG -name*.txt

when this command is entered a prompt will come for cnfirmation, ti delete sample.txt or not. ir you enter y/y it will delete the file

$ ./GFG -name sample.txt -exec rm -i {} \;

search for empty files and directories

$ find./GFG -empty

search the file with entred permission

$ find ./GFG -perm 664

search text within multiple lines

$ find ./-type f -name "*.txt" -exec grep 'geek' {}\;

find files using name and ignoring cases

$ find /home -iname tecmint.txt

find all read only files

$ find / -perm/u=r

find executable files

$ find /-perm/ a=x

find size between from xMB - y MB

$ find / -size + xM-size -yM

find size between from xMB - y MB

$ find / -size + xM-size -yM

find and remove single file

$ find .type f -name "techmint.txt" -execrm -f {}\;

find all empty directories

$ find /tmp -type d -empty

find all hidden files

 

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

find all files which are modified more than 50 days and less than 100 days

find / -mtime +50 -mtime -100

to find all files which are changd in the last 1 hour

$ find /-cmin -60

to find all files which are changd in the last 1 hour

$ find /-cmin -60

search for sample.txt in GFG directory

$ find ./GFG -name sample.txt

it will give all file which have .txt at the end

$find ./gfg -name *txt

it is used to delete the file

$find ./GFG -name sample.txt -exec rm-i {}\;

tfind all empty files in the directory

$find ./GFG empty

find all files in the given directory with the given permissions

$ find ./GFG -perm 664

print line which have geek in them and type f specifies the input type is a file

$ find ./ -type f -name "*.txt"-exec grep 'geek' { }\;

searches directories with a specific name

$ -type d -name puttygen

find files within this modified range

find /-mtime +30 -mtime -90

files modified with less than a specific time

find / -cmin -30

check newly created files

find /-newer test.txt

find the files more than the given size

find / tmp -size 40k

search the folder for a partcular name and shows the results and one needs to ececute the command

find /tmp -iname *trial* -exec is -1d {};

DevOpsSchool
Typically replies within an hour

DevOpsSchool
Hi there 👋

How can I help you?
×
Chat with Us