Computing.Net > Forums > Unix > Count files by date in a directory

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Count files by date in a directory

Reply to Message Icon

Name: ssadm
Date: October 15, 2009 at 14:24:16 Pacific
OS: UNIX
Subcategory: General
Comment:

Hello!

I'm wondering if some one could help me with the following with a UNIX shell scripting.

a) I want to count the files according to the date. Please find the details as follows,

Oct 15, 2009 - 3 files
Oct 14, 2009 - 2 files
.........
.........
Oct 14, 2008 - 4 files
........
........

I just need the files count on a particular day and the date should indicate the "Month Day, Year - No. of files" in the result. I tried, but i'm not able to get the year in the result.

Your help would be greatly appreciated.

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: October 15, 2009 at 14:55:01 Pacific
Reply:

How about sharing what you have, and we'll help you from there?


0

Response Number 2
Name: ssadm
Date: October 15, 2009 at 17:08:36 Pacific
Reply:

Hi Nails,

please find this.
ls -lt | grep "^-" | awk '{Date_count=$6" "$7; freq[Date_count]++}END {for (date in freq) printf "%s\t%d\n", date, freq[date] }'

i have this , but it's not giving me what i want. Please help me with this.

Thanks!!


0

Response Number 3
Name: nails
Date: October 16, 2009 at 14:53:58 Pacific
Reply:

You did the hard part. Remember that on legacy Unix systems that the ls command for the first 6 months shows the time instead of the year. (GNU ls has an option to show the year). Therefore you may have trouble with this script in the 4th quarter:

ls -lt | grep "^-" | awk '{
if($8 ~ /:/)
   $8=2009

Date_count=$6" "$7", "$8
freq[Date_count]++}
END {for (date in freq) printf "%s\t%d\n", date, freq[date] }'


1

Response Number 4
Name: ssadm
Date: October 19, 2009 at 10:49:16 Pacific
Reply:

Hi Nails!

This is great solution for my issue. I have tried your modified script and i get results as i expected even though the year doesn't show up for the first 6 months, and i'm happy for that.

Thank you.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Count files by date in a directory

Merging files in a directory www.computing.net/answers/unix/merging-files-in-a-directory/7781.html

Order by Date MM/DD/YY Help Urgent www.computing.net/answers/unix/order-by-date-mmddyy-help-urgent/5576.html

Need to convert the date in a SQUID www.computing.net/answers/unix/need-to-convert-the-date-in-a-squid/3877.html