You are here
Home > Redhat > Find commands

Find commands

1. Find every file under the directory /home owned by the user “sa”

             #find /home -user sa

2. Find the file “sample.txt” from the /

            #find / -name sample.txt

3. Find the file from current directory

            #find . –name <file name>

4. Find the file “*.c” under the folder /usr

           #find /usr -name *.c

5. Find all the files in the current directory

          #find . –type f

6. Find all the subdirectories in a directory

         #find . –type d

7. Find all symbolic links in /usr directory

        #find /usr –type l

8. Find the files which file permission “664”

        # find . –perm 664

-atime n -> File was last accessed exactly “N” Days

-mtimen -> File was last modified exactly “N” Days

-newer file -> File was modified more recently than file was

9. Find files that last modified less than 2 days ago

        # find / -mtime -2

10. Find the files that last modified more than 7 days ago

          # find / -atime +7

11. Find the files was modified more recently than file was

          # find –newer sample.txt

12. Find the file that permission sets 777 in home directory

          # find /home/ –perm 777

13. Find the files that based on owner of the files [ Here the is “sa” ]

          # find / –user sa

14. Find the file permission 777 and remove the same

          # find /home –perm 777 –exec –rm -f {} ;
15. Find every file under the directory /var/spool that was modified more than 60 days ago.

          # find /var/spool -mtime +60

Leave a Reply

eight − 3 =