One of my favorite pieces of software on windows is a little app called treesize free by Jam Software. It basically gives you a simple list of how much disk space each directory is taking up. This is really useful when you are trying to work out where all the space on your 500gig disk is gone.
I am always finding myself looking for similar piece of software for linux which can be run simply from the command line, but alas none exists so i decided to create a simple shell script to do a similar job, and here it is :
#/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; } '
Just put this code into a file /bin/treesize and make it executable. Then any system user can get a list of directory sizes within a directory by just running treesize from any directory.
Thanks so much for your script! I also like Treesize and had been looking for a Linux shell equivalent.
Awesome Script… works exactly as how I needed…
Thanks for sharing.
Thanks 🙂 . The script is very helpful
Awk! I miss awk!
The post is a bit old, but anyways. 🙂
Even though it’s elegant, your script is a bit overkill. du has this functionallity built in.
du -sch ./*
Thanks for the script, very useful.
I used to use du -sm * | sort -nr but this is much quicker, particularly if I change the max-depth parameter if required.
Hello !
Thank you VERY MUCH !
I am used to use Treesize for Windows too, and I needed the same think for my Synology NAS.
The only change is the “du” command :
du -k -d 1
Thank you!
Hey, thanks for the script.
for linux you can try the “baobab”
Great! This is so helpful in working on ubuntu server via console or ssh. I’m supposed to try to avoid using GUI for my class assignments, and even in my personal work (like trying to figure out what on earth is taking up my virtual hdd’s space!) I’m trying to be all command line.
some newer systems:
du -shx ./* | sort -h
It is not the treesize that way but excludes other file systems (x) summarizes sub-dirs (s) and sorts human readable. (if available in the sort there)
Thank you! It did the trick.
spooky… almost exactly a year later i need this again, please never ever let this page 404.
Excellent Script i like so much.
easy & simple
+1 thanks@!
Pingback: Treesize für Linux Script | µBrain-Blog
Thanks a lot ! Very helpfull script 🙂
Thanks 😉
There is also a very good diff-capable du-browser available: http://gt5.sourceforge.net/
After scanning a directory you can browse through a command line browser through your directory.
Try Filelight 😉
Excellent and simple… thanks a lot…
I personally prefer ‘ncdu’ (https://dev.yorhel.nl/ncdu/scr). It’s available on most distro’s.
Other options (copy/paste from ncdu site):
gt5 – Quite similar to ncdu, but a different approach.
tdu – Another small ncurses-based disk usage visualization utility.
TreeSize – GTK, using a treeview.
Baobab – GTK, using pie-charts, a treeview and a treemap. Comes with GNOME.
GdMap – GTK, with a treemap display.
Filelight – KDE, using pie-charts.
KDirStat – KDE, with a treemap display.
QDiskUsage – Qt, using pie-charts.
xdiskusage – FLTK, with a treemap display.
fsv – 3D visualization.
Philesight – Web-based clone of Filelight.
Thanks to Robin, for ncdu suggest
nice one
Already installed in all my linux servers
I use this a ton: “du -h –max-depth=1”
Thanks !
But I find this command easier to use:
for X in $(du -s * | sort -nr | cut -f 2); do du -hs $X ; done
This script file is cool, but i personnally prefer ncdu (thanks robin), because of treeview
Here’s another useful one: “sudo du -sh * | sort -h”