bash du with byte size in decimals to the nearest thousandth -


is possible in bash "du" command byte size shown in decimals.

for example, have following files (numbers in bytes):

12345 file1 2345 file2 6491 file3 

i "du" command in linux output following instead:

12.3 file1 2.3 file2 6.5 file3 

note: "-h" flag not work.

you should able use awk this, like:

du -b * | awk '{printf "%10.1f %s\n", $1/1000, $2}' 

as in following transcript:

pax> ls -l total 3092 -rwxrwxrwx  1 pax   pax       807 2008-09-14 08:26 combo.pl* -rwxrwxrwx  1 pax   pax       236 2008-09-14 08:26 match.pl* -rwxrwxrwx  1 pax   pax       754 2008-09-14 08:26 mkdb.pl* -rwxrwxrwx  1 pax   pax       689 2008-09-14 08:26 nine.pl* -rwxrwxrwx  1 pax   pax   2089522 2008-05-25 21:06 words.db* -rwxrwxrwx  1 pax   pax   1044761 2008-05-25 21:06 words.txt*  pax> du -b * 807       combo.pl 236       match.pl 754       mkdb.pl 689       nine.pl 2089522   words.db 1044761   words.txt  pax> du -b * | awk '{printf "%10.1f %s\n", $1/1000, $2}'        0.8 combo.pl        0.2 match.pl        0.8 mkdb.pl        0.7 nine.pl     2089.5 words.db     1044.8 words.txt 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -