Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am really fond of du, and I often like to use it like this:

$ du -hsc /var/mail/ /var/log/ 2>/dev/null 
4,0K    /var/mail/
5,7M    /var/log/
5,7M    total

However, I'd like to be able to print out sizes in format "[bytes] [kbytes]K [mbytes]M"; and as far as I can see, I cannot do that:

$ du -hscb /var/mail/ /var/log/ 2>/dev/null
4096    /var/mail/
14734462    /var/log/
14738558    total

$ du -hsck /var/mail/ /var/log/ 2>/dev/null
4   /var/mail/
5764    /var/log/
5768    total

$ du -hscm /var/mail/ /var/log/ 2>/dev/null
1   /var/mail/
6   /var/log/
6   total

$ # all (b,k,m) here: 
$ du -hscbkm /var/mail/ /var/log/ 2>/dev/null
1   /var/mail/
15  /var/log/
15  total

The k,b,m switches simply choose a block size, and then a prefix (K, M) is not even printed (and when you run them all together, you get some weird sizes reported).

Any ideas if there is something like a size format specifier string for du?

Many thanks in advance for any answers,

share|improve this question
up vote 2 down vote accepted

Your 'du' options are not portable anyway, so just use 'du' and write the suffix after arithmetics in awk for example.

share|improve this answer
Thanks for confirming that there isn't anything like a format specifier for du, @JiriXichtkniha - cheers! – sdaau Jun 11 '12 at 16:00
For example in AIX du doesn't have -h, so I use -m ;) – Jiri Xichtkniha Jun 11 '12 at 16:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.