Wednesday, April 9, 2014

How to find files on Linux

It give the full path of file find every where-------



Find at current location
# find    / -name abc.txt   

Find file name case insensitively
# find / -iname abc.txt   

Find the file in / .
# find / -name *.txt       

Find the file where 'pass' in /etc
# find /etc -name *pass*   


Find the file in /data created by macho
# find / -user macho       

Find the file in /data which is not created by macho
# find / -not -user macho   

Find the file with uid of 500
# find / -user macho -uid 500   

Matches if mode is exactly 755
# find / -perm 755       

Matches if anyone can write
# find / -perm +222       

Matches if everyone can write
# find / -perm -222       

Matches if other can write
# find / -perm -002          

Files with a size of exactly 10M
# find / -size 10M       

Files with a size of above 10M
# find / -size +10M       

Files with a size of less than 10M
# find / -size -10M       

When file was last read (min)
# find / -amin 10       

When file data last changed
# find / -mmin -10       

When file data or metadata last changed
# find / -cmin 10       

By this commnad linux find only file with exetantion .txt and
copy again with .doc ( -exec not ask to do )
# find / -name "*.txt" -exec cp {} {}.doc \;
   
Linux find only those file with permisssion 002 and execute
it again 777 ( or full permission )
# find / -perm -002 -exec chmod 777 {} \;
   
    -exec     execute directly
    -ok    asking to do

# find / -name "*.doc" -ok rm {} \;

Thanks,
Vishal Vyas

1 comment:

  1. Find any file containing string "FOO" from current location:
    # find ./ | xargs grep FOO

    ReplyDelete