Wednesday, 20 April 2011

Search your files in linux directory


Search
Locate
update database                                                           # updatedb                                                       [by superuser]
                                                                                    # locate file_name
                                                                                    # locate folder_name
                                                                                    # locate -i file_name
                                                                                    # locate -i passwd | less
                                                                                    # locate -i passwd | grep etc                             [etc releted passward search]
                                                                                    # lcoate -i -n 10 passwd                                     [matching first ten
                                                                                    # locate -i file_name                                          [i for case insensetive search]
                                                                                    # locate -n 10 file_name                                    [list first ten match]
                                                                                    # locate -e Dir1 Dir2 Dir3 ...                               [exclue directory]
.N.B must have read & execute permission on directories
Find
                                                                                    # find /
                                                                                    # find /home/tawheed
                                                                                    # find file_name
                                                                                    # find file_size
                                                                                    # find inode_number
                                                                                    # find time_stamp
Find & Fix file writable by other group                            # find / -perm -002 -exec chmod o-w {} \;                        [/ is starting poing, -perm argument of permission, -002 is value, -exec is execute without promt, chmod is command, o-w us argumet value, {} is find result, 'space\;' is termination]    
Find snow.png in current directory                                  # find -name snow.png
Find snow.png in current directory with case-insensetive # find -iname snow.png
Find files with .txt extention in entire directory                 # find / -name *.txt
Find files in /etc/ that contain pass in their name             # find /etc -name *pass*
Find files owned by user joe & group joe in /home/         # find /home -user joe -group joe
Find fies that hav W & .png in their nams                                    # find / -regex ".*W.*\.png"                                 [quote mark canbe omitted]
                                                                                    # find / -regex "W.*\.png"                                   [no reuslt & never be true]

 N.B must have read & execute permission on directories

No comments:

Post a Comment