Count of files based on date?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count of files based on date?
# 1  
Old 01-09-2007
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 Smilie
# 2  
Old 01-09-2007
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.
# 3  
Old 01-10-2007
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?
# 4  
Old 01-10-2007
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

Last edited by blowtorch; 01-10-2007 at 07:38 PM..
# 5  
Old 01-11-2007
Maybe not your requirement, but a general solution to count number of files as per date:
Code:
$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:
Code:
$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:
Code:
$./test1
Aug16   2
Jul30   3

Regards,
Tayyab
# 6  
Old 01-11-2007
checkout this

ls -ltr|grep "^-"|tr -s " "|grep -i 'jan 8'|cut -d " " -f7,8,10
# 7  
Old 01-11-2007
Thank you very much It worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split files based on row delimiter count

I have a huge file (around 4-5 GB containing 20 million rows) which has text like: <EOFD>11<EOFD>22<EORD>2<EOFD>2222<EOFD>3333<EORD>3<EOFD>44<EOFD>55<EORD>66<EOFD>888<EOFD>9999<EORD> Actually above is an extracted file from a Sql Server with each field delimited by <EOFD> and each row ends... (8 Replies)
Discussion started by: amvip
8 Replies

2. Shell Programming and Scripting

Extract count of string in all files and display on date wise

Hi All, hope you all are doing well! I kindly ask you for shell scripting help, here is the description: I have huge number of files shown below on date wise, which contains different strings(numbers you can say) including 505001 and 602001. ... (14 Replies)
Discussion started by: VasuKukkapalli
14 Replies

3. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

4. Shell Programming and Scripting

Need to count based on date

i have a file with data as follows: 3/23/2014 22:01:18 1 3/23/2014 22:01:47 0 3/23/2014 22:03:35 0 3/23/2014 22:04:50 1 3/24/2014 1:16:41 0 3/24/2014 1:18:00 0 3/24/2014 1:18:36 0 3/24/2014 1:21:46 0 3/25/2014 13:00:31 1 3/25/2014 13:00:54 0 3/25/2014 13:13:09 0 3/25/2014 13:14:15 0... (2 Replies)
Discussion started by: ssk250
2 Replies

5. Shell Programming and Scripting

Script To read Date and count from files

Smaple 1 Date and Time: 2013-05-11 12:23:12 MST abc,1234,hi-all,45354-88888,IN,US XYZ,1234,hi-all,45354-88888,OUT,GB abc,1234,hi-all,45354-88888,IN,AS abc,1234,hi-all,45354-88888,OUT,US abc,1234,hi-all,45354-88888,IN,US Number of Records: 000005 Sample 2 HDR: 20130511... (1 Reply)
Discussion started by: Abhisrajput
1 Replies

6. Shell Programming and Scripting

Find and count unique date values in a file based on position

Hello, I need some sort of way to extract every date contained in a file, and count how many of those dates there are. Here are the specifics: The date format I'm looking for is mm/dd/yyyy I only need to look after line 45 in the file (that's where the data begins) The columns of... (2 Replies)
Discussion started by: ronan1219
2 Replies

7. UNIX for Dummies Questions & Answers

Grep bunch of gzip files to count based on category

Started using unix commands recently. I have 50 gzip files. I want to grep each of these files for a line count based particular category in column 3. How can I do that? For example Sr.No Date City Description Code Address 1 06/09 NY living here 0909 10st st nyc 2 ... (5 Replies)
Discussion started by: jinxx
5 Replies

8. Shell Programming and Scripting

Shell Script to compare files, check current date and count

Hello - I have written the following basic shell script to count files, compare files and look for a particular strings in a file. Problem 1: How do I define more than 1 file location? #!/bin/bash #this is a test script FILES=$(ls /home/student/bin/dir1, home/student/bin/dir2)... (0 Replies)
Discussion started by: DallasT
0 Replies

9. Shell Programming and Scripting

Moving the files based on count and time.

Hi, I have a requirement ,let us say 1000 files needs to be transferred in an hour from one path to another path and if the files (1000 files) are transferred within an hour ( say 40 mins), then the process should remain idle for the remaining time ( 20 mins). (3 Replies)
Discussion started by: Asaikarthik
3 Replies

10. Shell Programming and Scripting

Get the newest files based on date

Hello friends, I'm learning to script, and I need help. How can I get the latest/newest files based on date? the format is as following: Feb 07 19:25 TESTPWD_file_1vk6pn40_19519_1 Feb 07 19:46 TESTPWD_file_1uk6pn40_19518_2 Feb 07 19:47 TESTPWD_file_20k6pn40_19520_2 Feb 07 19:56... (5 Replies)
Discussion started by: Beginer0705
5 Replies
Login or Register to Ask a Question