Solved How to count the no.of files created on a particular date ?

February 1, 2016 at 06:03:43
Specs: Windows 7
ls -ltr|grep "^-"|tr -s " "|grep -i 'Feb 1'|cut -d " " -f7,8,10 |wc -l

This command works for listing all files created in one particular directory and on particular date i.e., on Feb 1.

Sekhar & Ganesh


See More: How to count the no.of files created on a particular date ?

Report •

#1
February 2, 2016 at 06:36:36
✔ Best Answer
First, the ls command has a -R recursive mode that search all directories under the current directory. Does this work for you:

ls -ltrR ....

Second, do you realize that grep for 'Feb 1' also finds, Feb 11, Feb 12, etc.

So consider using the find command:

#!/bin/ksh

find . -type f -print| xargs ls -ltr | awk ' BEGIN { dd=1; mon="Feb"; cnt=0 }
{  #field 6 is the month and field 7 is the day.
if($6 == mon && $7 == dd)
   cnt++

} END { print cnt } '

The awk script does the actual counting of the files.

On my Solaris system, the 6th and 7th fields are the month and day respectively with the ls command:

-rw-rw-r-- 1 nails dev 240 Aug 4 2015 datafile.txt

On your system, it might be different.

Let me know if you have any questions.

message edited by nails


Report •
Related Solutions


Ask Question