Sum of file sizes generated in particular month and year
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
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
schneidz gave a warning: it's not a good idea to use the output of ls. The date format may vary and in this case, files more recent than 6 months don't show the year, therefore the grep statement returns nothing. You may use some options of ls to customize the appearance of the timestamp, but I would rely on the find solution, instead.
Not necessarily. You can run them on the command line. Take in mind that the leading $ sign is the command prompt (you don't have to type it). To test the results of the find command, run it without the -printf statement and without the awk part. Maybe using -ls, that is:
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.
What's wrong with the touch and find solution? You have just to set the proper dates in the touch commands (my example was based on your initial requirement Jan 2012, changed later to Feb 2012).
Quote:
Originally Posted by vdamgo
-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)
I don't think so. They appear to be created on February 2013. You can verify it using the stat command or the --full-time option of ls:
Code:
$ ls -l --full-time dummy1.txt listfiles.txt
$ stat dummy1.txt listfiles.txt
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.