Treesize Output in Linux

By just Another Techy / On / In Linux

One of my favourite programs in Windows is the free utility from JAM Software, TreeSize free, it integrates into the Windows shell allowing you to right click on any drive or folder and display an overview of the space used and whats consuming it.

TreeSize Free
TreeSize Free

I wanted to emulate this in the Linux shell and found a few ways to do it.

du – estimate file space usage

One way to do it in Linux is to emulate it using the ‘du’ command, there are a few ways to do this but by far the best I’ve seen so far is a script written by Andrew Clarke.

Run the following in your CLI

root@srv:/var# wget http://pastebin.com/raw.php?i=kW7yK0gC -q -O - | tr -d '\r' > /bin/treesize
root@srv:/var# chmod a+x /bin/treesize

and test it

root@srv:/var# treesize
877.8 MB .
624.0 MB ./cache
210.9 MB ./lib
24.0 MB ./crash
9.4 MB ./www
6.4 MB ./log
2.9 MB ./backups
80.0 KB ./spool
32.0 KB ./mail
4.0 KB ./tmp
4.0 KB ./opt
4.0 KB ./local
4.0 KB ./games
root@srv:/var#

durep – disk usage report generator

Another way to do it is to use the ‘durep’ command, this may need to be installed on your machine, on Ubuntu you can do this with

root@srv:/home# apt-get install durep

Once installed you can test it

root@srv:/var# durep -td=1
[ /var   845.2M (2 files, 12 dirs) ]
 621.3M [######################        ]  73.52% cache/
 187.4M [######                        ]  22.17% lib/
  24.0M [                              ]   2.84% crash/
   6.1M [                              ]   0.72% log/
   3.5M [                              ]   0.41% www/
   2.8M [                              ]   0.34% backups/
  21.2K [                              ]   0.00% mail/
    36b [                              ]   0.00% spool/
     9b [                              ]   0.00% lock
     4b [                              ]   0.00% run
     0b [                              ]   0.00% opt/
     0b [                              ]   0.00% local/
     0b [                              ]   0.00% tmp/
     0b [                              ]   0.00% games/
root@srv:/var#

If you want to script it paste the following into your CLI

root@srv:/# wget http://pastebin.com/raw.php?i=DLHeB6ne -q -O - | tr -d '\r' > /bin/treesize
root@srv:/# chmod a+x /bin/treesize

You can then user the ‘treesize’ command from any directory

root@srv:/var# treesize
[ /var   845.2M (2 files, 12 dirs) ]
 621.3M [######################        ]  73.52% cache/
 187.4M [######                        ]  22.17% lib/
  24.0M [                              ]   2.84% crash/
   6.1M [                              ]   0.72% log/
   3.5M [                              ]   0.41% www/
   2.8M [                              ]   0.34% backups/
  21.2K [                              ]   0.00% mail/
    36b [                              ]   0.00% spool/
     9b [                              ]   0.00% lock
     4b [                              ]   0.00% run
     0b [                              ]   0.00% opt/
     0b [                              ]   0.00% local/
     0b [                              ]   0.00% tmp/
     0b [                              ]   0.00% games/
root@srv:/var#

If you have anymore tips, please share!