CyberKeeda In Social Media
Showing posts with label find-grep. Show all posts
Showing posts with label find-grep. Show all posts

Linux Find Commands with examples.



Linux Find Commands Cheat sheet.

Find Files Using Name in Current Directory.
Lets assume we are currently under our /home directory.
  # find . -name myfile.txt
     /home/myfile.txt


Find Files Using Name and Ignoring Case ( Ignore upper & lower case )


  # find . -iname myfile.txt
     /home/myfile.txt
     /home/MYFILE.txt

Find Files under any specified Directory.


  # find . -iname myfile.txt

     /home/myfile.txt

     /home/MYFILE.txt


Find Files Using Name and Ignoring Case ( Ignore upper & lower case )

      #  find . -iname myfile.txt
    
         /home/myfile.txt
    
         /home/MYFILE.txt


    Find files  based on extention ( .php .txt .csv .sh )


      #  find . -type f -name "*.php"
    
         /home/myfile.php
    
         /home/index.php
    
    
    
     #  find . -type f -name "*.csv"
    
         /home/abc.csv
    
         /home/newfile.csv
    
    
    
     #  find . -type f -name "*.sh"
    
         /home/myscript.sh
    
         /home/new.sh
    
    
    
    
    


    Find Directories 


      #  find . -type d -name  mydirectory
    
    
        /home/mydirectory


    Find files with 777 Permission


      #  find /home   -type f -perm 0777 -print
    
          /home/abc.txt

    Find files without  755 Permission


       #  find /home  -type f ! -perm 755
    
           /home/myfile.txt
    
           /home/MYFILE.txt


    Find  all files Based on User
    We will find all files placed within /home directory having ownership of user jackuna
      #  find /home -user jackuna
    
          /home/myfile.txt


    Find  all files based on specific Group
    We will find all files placed within /home directory having group of user sysadmins
      #  find /home -group sysadmins
    
          /home/admin.sh


    Find  specific file type for a user
    We will find all files with .txt extension for user jackuna under /home directory
      #  find /home -user jackuna -iname "*.txt"
    
         /home/myfile.txt


    Find all empty files ( no content )
    We will find all empty/blank files  under /tmp directory.
       #  find /tmp -type f -empty


    Find all empty directories ( no content )
    We will find all empty/blank directories  under /tmp directory.
       #  find /tmp -type d -empty


    Find all hidden files
    We will find all hidden files under /tmp directory.
       #  find /tmp -type f -name ".*"


    Find  and remove a single file
    We will find file named as  myfile.txt  under /home directory and remove it permanently 
      #  find /home  -type f -name "myfile.txt" -exec rm -f {} \;


    Find  and remove a multi[ple file
    We will find all files with .sh and .mp3 extension under /home and delete it permanently 
      #  find /home -type f -name "*.sh" -exec rm -f {} \;
     
      #  find  /home  -type f -name "*.mp3" -exec rm -f {} \;


    Find files that are older then n number of days 
    Below find command will find all files that are older then 20 days under /tmp directory
      #  find  /tmp -mtime +20 -print
    


    Find files that are accessed then n number of days before
    Below find command will find all files that are accessed  20 days before under /tmp directory
      #  find  /tmp -atime +20 -print


    Find files that are changed within last hour
    Below find command will find all files that are changed within last 60 min under /tmp directory
      #  find /tmp -cmin -60


    Find modified files in last 60 minutes
    Below find command will find all files that are modified within last 60 min under /tmp directory
      #  find /tmp -mmin -60


    Find accessed files in last 60 minutes
    Below find command will find all files that are accessed within last 60 min under /tmp directory
      #  find /tmp -amin -60

    
    
    Read more ...
    Designed By Jackuna