Count of files based on date?

Hi Friends,

Can anyone help me with this:
To get the count of files that are existing in a directory created on a perticular date like in the example (01/08) .(having same pattern for the filename)

ex:
FileName Creted Date

FILE001 01/08/2007
FILE005 01/06/2007
TXT003 01/08/2007
FILE005 01/08/2007

I need count i.e "2" (FILE001 and FILE005 created on 01/08)

I have used ls -l | grep -c ^- It is retrieving all the files in the directory,

Thanks in advance

Sam :slight_smile:

Of course it is retreiving all the files. In your command you are just running 'ls -l|grep -c ^-'. This lists all files in the directory, then just filters out plain files (removes dirs/pipes/devices).
You'll need to filter for files created on the 8th first to do what you want. Use find or grep to get the files that you want first and then run the count.

I have tried using find

find . -name FILE001*.* | grep -c ^
It gives an error can you please correct me.

How can we filter the files based on the created date?

If you know the date, and are running manually, you can just grep for the date:
ls -l | grep -c "Jan 8"

-Edit
Better:
find . -type f | xargs ls -l | grep -c "Jan 8"
To prevent descent into subdirectories, just search the site for non-recursive find or something like that
-/Edit

Maybe not your requirement, but a general solution to count number of files as per date:

$cat test1
#!/bin/ksh
ls -l | grep "^-" | awk '{
key=$6$7
freq[key]++
}
END {
for (date in freq)
        printf "%s\t%d\n", date, freq[date]
}'

Here is some sample input:

$ls -l | grep "^-"
-rw-r--r--    1 admin    other             0 Jul 30 12:31 test.cpp
-rw-r--r--    1 admin    other             3 Aug 16 07:56 test.cpp.z
-rw-r--r--    1 admin    other             0 Jul 30 12:31 test.txt
-rw-r--r--    1 admin    other             0 Jul 30 12:31 test1.cpp
-rw-r--r--    1 admin    other             3 Aug 16 07:56 test1.cpp.z

Output:

$./test1
Aug16   2
Jul30   3

Regards,
Tayyab

checkout this

ls -ltr|grep "^-"|tr -s " "|grep -i 'jan 8'|cut -d " " -f7,8,10

Thank you very much It worked.