CyberKeeda In Social Media
Showing posts with label FIND. Show all posts
Showing posts with label FIND. Show all posts

Linux - Count no of files in a folder by day.

 


One Liner to count the number of files in a directory by date.

We often got this requirement where we have to deal with file counts, we have a huge list of files within a folder and we want to count the number of files created by date.

One Liner Linux CLI command

# find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c

 
Output for above command will look something like below.

1 2019-07-03 1 2019-08-08 6 2019-08-13 1 2019-08-15 1 2019-09-10 2 2019-09-11 1 2019-09-23 1 2019-10-22 1 2019-10-25 1 2019-10-29 1 2019-12-05 1 2020-03-04 2 2020-03-30 1 2020-04-07 11 2020-04-08 2 2020-04-09 1 2020-04-21 1 2020-04-26 2 2020-04-30 430 2020-05-06 1 2020-05-20 4 2020-05-26 951 2020-07-01 434 2020-07-02 1 2020-07-05 2 2020-07-06 100 2020-07-15 1 2020-07-28 6 2020-07-29 1 2020-08-01 2 2020-09-03


Let's break out the command and understand one by one highlighted in pale Yellow.

find . -type f

# find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c

Find . -type f 

Find command will fetch only the files ( -type f ) within present directory ( . )


-printf '%TY-%Tm-%Td\n'

# find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c

-printf '%TY-%Tm-%Td\n' will prints the modification time of files in e.g. 2020-04-26 format

sort | uniq -c
# find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c

sort : It will sorts the output 
uniq -c : It will count the sorted output by date.


Feel free to use it,  thank me later ;)

Read more ...

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