Ubuntu – Count number of files in a folder per day

command linefind

I can find number of all files in folder but I got pretty large number.

find . -type f | wc -l      #find number of files in DIR
ls -lrt                     #list all files order by date  

How to find number of files par day?

So, the result should be something like:

# left number is number of files and right is one day.

109294 2016-06-27
101555 2016-06-26
88123  2016-06-25 
... etc. 

Best Answer

You can do this using the printf action of find to print only the modification times in desired format, and then using sort and uniq:

find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c
  • -printf '%TY-%Tm-%Td\n' prints the modification time of files in e.g. 2015-05-23 format

  • sort sorts the output and uniq -c does the count by date

Example:

~/foobar% find . -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c
      3 2004-06-29
      1 2004-08-23
      1 2004-09-15
      1 2004-09-18
      1 2005-07-24
      1 2006-02-05
      2 2008-06-25
      3 2008-12-31
      1 2009-03-13
      1 2009-04-30
      1 2010-04-04
      2 2010-09-01
      8 2011-07-13
     15 2011-08-27
      3 2011-11-03
      3 2014-10-08
Related Question