Yogsototh

get disk usage by file type

Posted in geek by yogsototh on March 18, 2009

A simple and usefull script to evaluate usage of your disk by filetype. Should be improved
to manage extension with more than 3 letters. For this you can just replace the /\.{2,3}$/ by

/\..{2-6}$/ to accepts extension from 2 to 6 letters long.

#!/usr/bin/env zsh
if (($#<1)); then
    cible='.'
else
    cible=( "$@" )
fi
find $cible -type f -exec du -k {} \;  |  awk --posix '
{
    if ($2 ~ /\.[^/]{2,3}$/) {
        ext=$2;
        sub(/.*\./,"",ext);
    } else {
        ext="withoutExtension";
    }
    taille[ext]+=$1 ;
    nb[ext]++ ;
}
END{
    for (x in taille) {
        printf "%10d ", nb[x];
        print x" for "taille[x]" Ko";
    }
}' | sort -n

hope this is usefull

Blogged with the Flock Browser
Tagged with: , , ,

Leave a Reply