Disk usage by file type

2015-11-30 116 words 1 min read

Trying to find the total usage for each of the file types by extension, then here is a quick bash function for you :

disk_usage_type () 
{ 
    find . -name '*'$1 -ls | awk '
    BEGIN{
        a[0]="Bytes";
        a[1]="KB";
        a[2]="MB";
        a[3]="GB";
    }
    {sum+=$7; files++;}
    END{
    print "Total sum is ::\t" sum;
    print "Total files  ::\t" files;
        while (sum > 1024) {
            sum=sum/1024;
            count++;
            };
        print sum" "a[count];
    }'
}

Just define the function in one of your bash startup files. After that to use the function pass in the extension for which you would like to find the total size. Output should be something like below:

Total sum is ::    2586694320
Total files  ::    149
2.40905 GB

 


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it