calculate directory size by year of file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers calculate directory size by year of file
# 8  
Old 09-25-2006
Quote:
Originally Posted by igidttam
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]

pls start using code tags.

Code:
find . -type f -follow -ls | nawk -v yearNOW=$(date +%Y) '{year= (index($10, ":")) ? yearNOW : $10; arr[year] += $7} END {for (i in arr) printf("%s -> [%d]\n", i, arr[i])}'


Last edited by vgersh99; 09-25-2006 at 06:14 PM.. Reason: added '-follow' to follow the symboilc links
# 9  
Old 09-25-2006
I ran your code and received the results by year. It doesn't look correct.
I see years 2004 - 2006 have the same value. This couldn't be correct.

find . -type f -ls | nawk -v yearNOW=$(date +%Y) '{year= (index($1
, ":")) ? yearNOW : $10; arr[year] += $7} END {for (i in arr) printf("%s -> [%d
\n", i, arr[i])}'

2003 -> [1736530393]
2004 -> [2147483647]
2005 -> [2147483647]
2006 -> [2147483647]
# 10  
Old 09-25-2006
Quote:
Originally Posted by igidttam
I ran your code and received the results by year. It doesn't look correct.
I see years 2004 - 2006 have the same value. This couldn't be correct.

find . -type f -ls | nawk -v yearNOW=$(date +%Y) '{year= (index($1
, ":")) ? yearNOW : $10; arr[year] += $7} END {for (i in arr) printf("%s -> [%d
\n", i, arr[i])}'

2003 -> [1736530393]
2004 -> [2147483647]
2005 -> [2147483647]
2006 -> [2147483647]
once again..... if you need to post code, surround the code with the 'code' tag - see my previous link on how to use the tags.

if you're directing your question towards a given poster, PLS do quote the original post you're replying to OR post the name you're directing your reply to.

as for your output..... what OS are you on?
pls post a sample output of the 'find . -type f -ls' command to see the format of your 'find'.

the above solution worked fine under Sun/Solaris.
# 11  
Old 09-25-2006
here's a slightly modified script to follow the 'symbolic links' for 'find':
Code:
find . -type f -follow -ls | nawk -v yearNOW=$(date +%Y) '{year= (index($10, ":")) ? yearNOW : $10; arr[year] += $7} END {for (i in arr) printf("%s -> [%d]\n", i, arr[i])}'

# 12  
Old 09-25-2006
Alternative in Python:
Code:
#!/usr/bin/python

import os,stat,time
year = {} #store year calc
for files in os.listdir("."):
 	if not os.path.isfile(files):    continue
 	properties = os.stat(files)
 	size, t = properties[6], properties[stat.ST_MTIME] #get file size, modified time
 	yr = time.ctime(t)[-4:] #get year
 	if not year.has_key(yr): year[yr] = 0
 	year[yr] += size	

for i,j in year.iteritems():
     print "Year: %s, Size: %s" %(i,j)

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

2. Shell Programming and Scripting

How to calculate the total number of weeks from a specify year?

Hi anyone can help? How to calculate total number of weeks from a specify date, for example, 01 Jan 2012. Thx! (2 Replies)
Discussion started by: rayray2013
2 Replies

3. Programming

[c] How to calculate size of the file from size of the buffer?

Hi, Can I find size of the file from size of the buffer written? nbECRITS = fwrite(strstr(data->buffer, ";") + 1, sizeof(char), (data->buffsize) - LEN_NOM_FIC, fic_sortie); Thank You :) (1 Reply)
Discussion started by: ezee
1 Replies

4. Shell Programming and Scripting

Find a particular directory in multiple file systems and calculate total size

Hello : I need some help in writing a ksh script which will find a particular directory in all the file systems in a server and finally report the total size of the direcotry in all the file systems. Some thing like this.. find /u*/app/oracle -type d -name "product" -prune and then... (1 Reply)
Discussion started by: Sam1974
1 Replies

5. Shell Programming and Scripting

How to delete some of the files in the directory, if the directory size limits the specified size

To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Discussion started by: shaal89
0 Replies

6. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

7. UNIX for Dummies Questions & Answers

move all 2008 year's file to destination directory

I am trying to move file created/modified in 2008 year to <new directory>. But trapped badly in Xargs {}. Looks like mv is not getting destination file properly. It assumes source file s to be destination directory n gives me erroir. "Target must be a directory" Run- #/home/mktrisk: find... (4 Replies)
Discussion started by: kedar.mehta
4 Replies

8. UNIX for Dummies Questions & Answers

Create Year directory, date subdirectory and archive the file

Hi, After checking all the UNIX threads, I am able to come up with a solution so far. I am working on a shell script where it moves the files to a certain directory. The conditions to check are 1) Check if the file exists in the current directory. 2) Check if the destination directory... (2 Replies)
Discussion started by: madhunk
2 Replies

9. Shell Programming and Scripting

How to calculate file's size in directory and subdirectory

Hi, I have written one script to calculate total space of all file in one directory, ignoring subdirectory, it works fine. Now, I've been trying to calculate all files which includes files in any subdirectories. I use recursive function to do this, but it can work only if there is only one... (4 Replies)
Discussion started by: KLL
4 Replies

10. UNIX for Dummies Questions & Answers

how to calculate the file size?

HI, Can somebody please tell me how many bytes make a KB & MB. ThANKS. Rooh.:( (3 Replies)
Discussion started by: rooh
3 Replies
Login or Register to Ask a Question