The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to know size of file in a directory kittusri9 Shell Programming and Scripting 1 04-28-2008 09:43 AM
Create Year directory, date subdirectory and archive the file madhunk UNIX for Dummies Questions & Answers 2 12-13-2007 11:25 AM
calculate size of some files big123456 Shell Programming and Scripting 11 07-22-2005 06:07 PM
How to calculate file's size in directory and subdirectory KLL Shell Programming and Scripting 4 10-16-2003 08:02 AM
how to calculate the file size? rooh UNIX for Dummies Questions & Answers 3 08-17-2001 02:45 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-25-2006
igidttam igidttam is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 22
calculate directory size by year of file

I need to calcualte the size of a directory [and all it's subdirectories] by the year the files in that directory were created [or last accessed].
For example the script will sum up, by year, the number of blocks for that directory and its' subdirectories for files created / accessed in that year.

I need a report that would look like this :-
year 2000 50000 blocks
year 2001 2000 blocks
year 2002 45000 blocks
year 2003 150 blocks ...etc...etc thru year 2006.

I think I need to do this usings awk, but I'm not certain.

any ideas?

Thanks,
igidttam
  #2 (permalink)  
Old 09-25-2006
igidttam igidttam is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 22
I'm close but I don't have it right yet.
The code below prior to the pipe du -ks gives me all the files for 2002.
I just want the total bytes for those files for 2002

ls -rRl | awk '$8=="2002" ' | du -ks


Thanks
igidttam
  #3 (permalink)  
Old 09-25-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,128
Code:
find . -type f -ls | nawk '{arr[$8] += $7} END {for (i in arr) printf("%s -> [%d]\n", i, arr[i])}'
  #4 (permalink)  
Old 09-25-2006
igidttam igidttam is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 22
If I use this, I get the total at the end. This worked for 2003 files

ls -rRl | awk '$8=="2003" ' | du -k -a
  #5 (permalink)  
Old 09-25-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
du command won't take input which you passed through pipe
  #6 (permalink)  
Old 09-25-2006
igidttam igidttam is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 22
yes I realize that now. Do you know how I can accomplish this?
  #7 (permalink)  
Old 09-25-2006
igidttam igidttam is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 22
I tried your code and it doesn't total by year. It does it by month.
Looks like it's all the same. There should be a different number of total bytes per year


> find . -type f -ls | nawk '{arr[$8] += $7} END {for (i in arr) prin
tf("%s -> [%d]\n", i, arr[i])}'

Apr -> [2147483647]
Jun -> [2147483647]
5 -> [0]
25 -> [0]
Oct -> [2147483647]
Sep -> [2147483647]
Nov -> [2147483647]
Mar -> [2147483647]
May -> [2147483647]
Dec -> [2147483647]
Jan -> [2147483647]
Aug -> [2147483647]
Jul -> [2147483647]
Feb -> [2147483647]
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0