Unix command flag of the day
9

Unix command flag of the day

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’

9 thoughts on “Unix command flag of the day

  1. 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^)=

  2. 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’.

  3. …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.

  4. 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.

  5. 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

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>