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
# 1  
Old 09-25-2006
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  
Old 09-25-2006
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  
Old 09-25-2006
Code:
find . -type f -ls | nawk '{arr[$8] += $7} END {for (i in arr) printf("%s -> [%d]\n", i, arr[i])}'

# 4  
Old 09-25-2006
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  
Old 09-25-2006
du command won't take input which you passed through pipe
# 6  
Old 09-25-2006
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]
# 7  
Old 09-25-2006
yes I realize that now. Do you know how I can accomplish this?
 
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