Thursday, May 30, 2013

Linux Treesize Like Function

As a windows administrator, one tool in my arsenal to figue out where space is being consumed is TreeSize, today I was looking for a similar function in Linux and I came across this script.

#/bin/sh
du -k --max-depth=1 | sort -nr | awk '
     BEGIN {
        split("KB,MB,GB,TB", Units, ",");
     }
     {
        u = 1;
        while ($1 >= 1024) {
           $1 = $1 / 1024;
           u += 1
        }
        $1 = sprintf("%.1f %s", $1, Units[u]);
        print $0;
     }
    '


Create this file, save it as "treesize", make it executable and put it in your /bin folder. Then you can go to any directory and type treesize to list the sizes of the files and folders in that directory.

Credit goes to This Blog where I found this handy script.

No comments:

Post a Comment