Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create HTML disk usage trees from du output UNIX
duHTMLtree is a perl script that I wrote to render disk usage trees in HTML based on the output of the unix du command. The du output file can be generated once, and then duHTMLtree can render multiple trees without incuring the overhead of rumbling your disk for every tree. duHTMLtree can run either as a CGI or from the command line. OmniGroup's DiskSweeper may do something similar with a GUI, though I haven't looked at it.

Sample output can be seen here and here. Read the rest of the hint for the how-to...

Download it with:
curl -o duHTMLtree ''
# now make it executable:
chmod a+rx ./duHTMLtree
As A Command Line Script:
Generate a duk file with:
mkdir /tmp/disktree ; du -k /some/path/here > /tmp/disktree/duk_mydisk.txt
Then run duHTMLtree with, for example, these options:
./duHTMLtree -s500M '-tMy Disk Tree' -n'My Disk' -c1 \
 /tmp/disktree/duk_mydisk.txt > /tmp/mydisktree.html
and then open the resulting HTML file. duHTMLtree -h will show you command line options. The color strings are defined within the script, or you can also pass one on the command line. The obvious way to use it is to generate the duk files through a cron job, say nightly or weekly, possibly on multiple systems and then feed them to duHTMLtree to build whatever trees you want. If you want to build a single document with multiple trees, use the -b and -l options and build your own document header with relative links.

Note: The last update time is based on the modification time of the duk file so cp -rp or scp -rp is a good idea.

As a CGI:
It's much nicer to have a dynamic view, so that you can adjust the size and colors, etc., so duHTMLtree will also run as a CGI. Edit duHTMLtree and modify the configuration to match yours. In particular, the values for OK_REMOTE_IP and SCAN_DIR are important! The defaults are to use files from /tmp/disktree/duk_*, and to only permit access from and Then put it in your cgi-bin directory:
cp duHTMLtree /Library/WebServer/CGI-Executables \
 chmod a+rx /Library/WebServer/CGI-Executables/duHTMLtree
Make sure you have some duk_*.txt files in your SCAN_DIR and then browse to http://localhost/cgi-bin/duHTMLtree to see the output.
  • Currently 2.00 / 5
  You rated: 1 / 5 (4 votes cast)

Create HTML disk usage trees from du output | 4 comments | Create New Account
Click here to return to the 'Create HTML disk usage trees from du output' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create HTML disk usage trees from du output
Authored by: n8gray on Sep 28, '04 06:18:56PM

This is a really nice idea -- I was thinking of writing something similar myself. There's a bug somewhere, though. It fails if it runs across a file larger than 9999999 kB. To reproduce it, put this in a file called duk_test.txt:

9411552 /Users/n8gray/Music/iTunes/iTunes Music
9419124 /Users/n8gray/Music/iTunes
9762100 /Users/n8gray/Music
24924852 /Users/n8gray
27739736 /Users
52341586 /

(There should be tabs in between the numbers and the paths, by the way.) If you delete the last three lines it will work, but with them present it won't. I tried to figure out the problem, but it's hopeless for me to try to debug somebody else's Perl code. If it was Python, on the other hand... ;-)

[ Reply to This | # ]
Create HTML disk usage trees from du output
Authored by: n8gray on Sep 28, '04 06:53:55PM

My mistake -- it's actually only the last entry that causes problems. It's not the size of the numbers, it's the fact that the path is just '/'. I still don't know exactly what goes wrong.

[ Reply to This | # ]
Workaround for bug
Authored by: MartySells on Oct 07, '04 04:21:46AM
I fiddled with this a bit when it was posted and just now figured out the problem when doing some cross-platform disk trees. duHTMLtree does not like when the last entry ends with a /.

So when you call du do not end your argument with a trailing /. (du -k /Volumes/Foobar is good, du -k /Volumes/Foobar/ is not. Or post-process your du output to remove the last / on the last line of output.

The case in the above post appears to work if the last line is simply the size number followed by a tab (i.e. no path).


[ Reply to This | # ]
Create HTML disk usage trees from du output
Authored by: ar on Sep 29, '04 01:13:08AM
Another GUI diskspace viewer (freeware): Disk Inventory X

[ Reply to This | # ]