I just learned within the past 24 hours that the du command, which displays how much space a directory and all of its subdirectories are consuming supports the -h
flag, which prints the results in a human-comprehensible format. Here’s the output of du -d 1
in my Web root:
7494 ./clips 18986 ./mt 145234 ./cache 236 ./planetrafe 794 ./test 518 ./ofinterest 4 ./cgi-bin 324 ./templates_c 14 ./images 3596 ./mt-static 706 ./2007 6 ./assets_c 178090 .
Here’s the output of du -d 1 -h
:
7.3M ./clips 19M ./mt 142M ./cache 236K ./planetrafe 794K ./test 518K ./ofinterest 4.0K ./cgi-bin 324K ./templates_c 14K ./images 3.5M ./mt-static 706K ./2007 6.0K ./assets_c 174M .
If you use the Bash shell, you can save yourself some trouble by just creating an alias:
alias du=’du -h’
August 30, 2007 at 2:31 pm
The -h flag also works with the ls command.
August 30, 2007 at 3:25 pm
Works for df, too.
One of the things I love about UNIX is that being human-comprehensible is the non-default option.
August 30, 2007 at 4:14 pm
The problem with aliasing ‘du’ to ‘du -h’ is that then you can’t do ‘du -s * | sort -n’ to find the biggest directory.
You can however alias ‘duh’ to ‘du -h’… 8^)=
August 30, 2007 at 6:19 pm
I actually did think about the command line scripting implications when I suggested creating the alias.
I have always used ‘df -k’. I didn’t know about ‘df -h’.
August 30, 2007 at 9:58 pm
…and of course it doesn’t work on AIX. Nothing ever works on AIX, so I can never use neat tricks at work. I even had to learn vi, because that’s the only editor installed on half our systems.
August 30, 2007 at 11:51 pm
Somehow I never knew about -h until this day. Thanks.
August 31, 2007 at 7:59 am
Maybe it’s just me but I’ve tried learning vi at least a dozen times over the past 10 years and every time I just give up in frustration. I usually end up resorting to pico or nano.
August 31, 2007 at 1:07 pm
I was pleased to learn about -h several months back, but what I learned from your post is “-d 1”. I’d always done stupid stuff like for x in
ls -d
; do du -sh $x; done.slaps forehead
emacs emacs emacs
August 31, 2007 at 1:09 pm
Whoops, turns out “-d” doesn’t work on my du.