How-to: Treesize script for linux.

This is a simple Treesize Script for Linux. I take no credit for this script. I found it on the internet but it works very well so I am putting it here so I don’t loose it. Feel free to distribute. If you are the arthor of this script contact me and I will gladly give you credit for it here.

It is great for finding out what files and or directories are filling up your filesystem. It comes in handy quite a lot. Simply copy the code below into a file called treesize.sh and then make the script executable. To run the script simply call it from the root of the tree you want to examine and run ./treesize.sh.


#/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;
}
'


Posted

in

, , ,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *