Tuesday, June 4, 2013

To calculate the size of selected list of files in a directory

>>ls -l /mnt/dd_data/rawlogs/2013052004/federation_production/acc*
31216UTC.gz
-rw-r--r--  1 yahoo dev 38158188 May 20 11:43 /mnt/dd_data/rawlogs/2013052004/federation_production/access.fed1064.yss.ac2.yahoo.com.20130520041216UTC.gz
-rw-r--r--  1 yahoo dev 40594305 May 20 11:33 /mnt/dd_data/rawlogs/2013052004/federation_production/access.fed1064.yss.sk1.yahoo.com.20130520032713UTC.gz
-rw-r--r--  1 yahoo dev 39197951 May 20 11:34 /mnt/dd_data/rawlogs/2013052004/federation_production/access.fed1064.yss.sk1.yahoo.com.20130520042713UTC.gz
-rw-r--r--  1 yahoo dev 42180531 May 20 11:50 /mnt/dd_data/rawlogs/2013052004/federation_production/access.fed1065.yss.ac2.yahoo.com.20130520033334UTC.gz
-rw-r--r--  1 yahoo dev 35726770 May 20 11:53 /mnt/dd_data/rawlogs/2013052004/federation_production/access.fed1065.yss.ac2.yahoo.com.20130520043334UTC.gz
.
.
.
.
.
.

Now, to calculate the total size of these files, we can do as following:
>> ls -l /mnt/dd_data/rawlogs/2013052004/federation_production/acc* | awk '{SUM=SUM+$5; } END {printf "%10.0f\n", SUM}'
>>7962647332

This will give you size in bytes.
- If you want it in MBs, divide by 1024
- If you wanr it in GBs, divide by 1024*1024