Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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,
Cheers!

share|improve this question
add comment

1 Answer

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
1  
For example in AIX du doesn't have -h, so I use -m ;) –  Jiri Xichtkniha Jun 11 '12 at 16:02
add comment

Your Answer

 
discard

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.