![]() |
Sum of file sizes generated in particular month and year
Hi,
I am trying to find the sum of file sizes that ran in Jan 2012 from a directory and also group of directories. (folder has 1000's of files generated every month and every year, among all these files, i want to calculate the sum of file sizes in MB generated in Jan 2012, which also has files generated in Jan 2013 etc) Is there any script to find the sum of filesizes that ran on particular month and year. please let me know. Thanks! |
i think the find command should help (-ctime or -newer mite be useful parameters).
what have you tried and where are you stuck ? also the du command would probably help here. |
I tried the below statement
ls -lrt | grep "Jan " | awk -F" " 'BEGIN { sum=0} {sum+=$5} END {print sum}' But I have files Jan 2012 and Jan 2013 files in the directory but I just need sum file size of Jan 2013 files only |
Quote:
Code:
ls -lrt | grep "Jan.*2012 " | awk -F" " 'BEGIN { sum=0} {sum+=$5} END {print sum}' |
Using find - as previously suggested:
Code:
$ touch -t 201112312359 /tmp/file1 |
I think it did not work, I tried as below but it returned 0
[testserver@forfinding-or]/abcd/efg/ehome/karti>ls -lrt total 4 -rw-rw-r-- 1 pinto pinto 30 Feb 7 14:18 listfiles.txt -rwxrwxrwx 1 pinto pinto 124 Feb 7 14:54 test_file.sh -rw-rw-r-- 1 pinto pinto 0 Feb 7 15:05 ls [testserver@forfinding-or]/abcd/efg/ehome/karti>ls -lrt | grep "Feb.*2013" | awk -F" " 'BEGIN { sum=0} {sum+=$5} END {print sum}' 0 |
Quote:
|
Sorry, Am really poor in linux scripting, Do we need to keep the below statements in script and then execute
$ touch -t 201112312359 /tmp/file1 $ touch -t 201201312359 /tmp/file2 $ find . -type f -newer /tmp/file1 -not -newer /tmp/file2 -printf "%s\n" | awk '{sum += $0} END{print sum}' $ rm /tmp/file1 /tmp/file2 |
Quote:
Code:
$ touch -t 201112312359 /tmp/file1 |
I think we have lost somewhere, here is example as below, I have four files in a directory. two files got generated in feb 2012 and another two files in Feb 2013, now i want to sum up the file size gennerated in feb 2012 so answer should be 85+30=115
[pin@test-omf]/abcd/def>ls -lrt total 12 -rwxrwxrwx 1 pinot pinot 85 Feb 6 23:59 dummy1.txt (this file is generated in Feb 2012) -rw-rw-r-- 1 pinot pinot 30 Feb 7 14:18 listfiles.txt (this file is generated in Feb 2012) -rwxrwxrwx 1 pinot pinot 124 Feb 7 14:54 test_abcd.txt (this file is generated in Feb 2013) -rwxrwxrwx 1 pinot pinot 86 Feb 8 12:02 dummy2.txt (this file is generated in Feb 2013) The above is just an example, like wise I have 1000s of files in a directory which are mixed up like some are generated in year feb 2012 and some are generated in feb 2011, some are generated in feb 2013 etc, but am trying to find the sum of file sizes generated in feb 2012. |
Code:
ls -al | grep " 2012 " | awk -F" " 'BEGIN { sum=0} {sum+=$5} END {print sum}' |
Quote:
Quote:
Code:
$ ls -l --full-time dummy1.txt listfiles.txt |
Thank you.
I think it worked. $ touch -t 201112312359 /tmp/file1 $ touch -t 201201312359 /tmp/file2 $ find . -type f -newer /tmp/file1 -not -newer /tmp/file2 -printf "%s\n" | awk '{sum += $0} END{print sum}' $ rm /tmp/file1 /tmp/file2 Can you please give me little explanation like whats is the procedure and what the script is performing. Appreciate your help |
| All times are GMT -5. The time now is 11:57 AM. |