You are on page 1of 3

Play with find Command $find / -name searchFileName This is used to find the file name searchFileName from

the root directory $find. name searchFileName This is used to find the file name searchFileName from the current directory (where this command should executed) $ find . -type f -size 0 ls This is used to find files with zero size from current directory. $ find . -name "*.htm*" -type f This is used to find files end with .htm from current directory. $ find . -name "*" -type f -size +1000 This is used to find all files with size is greater than 1000k from current directory. $ find . -name foo.bar -type f 2> /dev/null This is used to find foo.bar file suppose it doesnot have any access permission it eliminate error message( 2>/dev/null). $ find . -type s This is used to find all socket files from current directory. $ find . -type d This is used to find all directory only. $ find . -type f This is used to find all normal files from current directory. $ find . -newer SK This is used to find all files after creating file name SK from current directory. $ find . -newer SK perm 777 This is used to find all files after creating file name SK from current directory that files must have all permission for all.

Finding all files owned by a user


$ find . -user applas

Find out all files owned by user applas $ find . -user applas name *.sh This is used to find all .sh files which are created by applas.

Finding files according to date and time


$find /home -atime +7

-atime +7: All files that were last accessed more than 7 days ago -atime 7: All files that were last accessed exactly 7 days ago -atime -7: All files that were last accessed less than7 days ago

$find /home -mtime +7


-mtime +7: All files that were last modified more than 7 days ago -mtime 7: All files that were last modified exactly 7 days ago -mtime -7: All files that were last modified less than7 days ago

The power of find


Find with grep $find . name *.txt exec rm {} \; This is used to find all .txt files and deleted all. $find . -name '123' -exec grep 'python' {} \ This is used to find python word in a file name 123 and it shows line which occur in a file. $find . -name '123' -exec grep -l 'python' {} \; This is used to find python word in a file name 123 and it shows the path of the file. Commands I found: 1. If you want to get the details of the file containing string 'string', you this grep -ir 'string' /dir/from/where/you/want/to/search 2. Did you want to list the file that had the word 'get'. Is that the string you are referring to? Se if this works for you 002D

find /dir/from/where/you/want/to/search -type f -exec grep -l 'get' {} \; 2>/dev/null

3. Quote: Originally Posted by ranj@chn Did you want to list the file that had the word 'get'. Is that the string you are referring to? Se if this works for you Code:
find /dir/from/where/you/want/to/search -type f -exec grep -l 'get' {} \; 2>/dev/null

Thanks dude, its been ages that i've searched for that kind of command! Knowing not the minus l option of grep, I used to Code:
find /dir/from/where/you/want/to/search -type f -exec cmd.sh 'get' {} \;

where cmd.sh is Code:


grep $1 $2 2>/dev/null [ $? -eq 0 ] && echo $2

To find the files that contain a string we can use: find . -exec grep -l string to find {} \; This starts the search from the current directory, looks for files that contain the specified string, and then it prints their names.

You might also like