bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: programs


From: Matthew Woehlke
Subject: Re: programs
Date: Thu, 07 Jan 2010 17:14:45 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.23) Gecko/20090825 Fedora/2.0.0.23-1.fc10 Thunderbird/2.0.0.23 Mnenhy/0.7.5.0

Juhapekka Tolvanen wrote:
On Thu, 31 Dec 2009, +14:51:44 EET (UTC +0200),
Eric Blake pressed some keys:

According to Juhapekka Tolvanen on 12/30/2009 4:35 PM:
I wanted to do this: Give sizes of each files and directories located
in $PWD in human-readable-format AND sort output according to sizes of
those files and directories.

What's wrong with:

du -sh0 * | sort -hz | tr '\0' '\n'

besides needing coreutils 7.5 or newer?

What if size of one directory is rounded UP to 1M and size of other
directory is rounded DOWN to 1M? How sort-command can know know, which
one is bigger? I am sure, that sorting must be done according to size
in bytes, not according to size of human-readable units.

Okay. What is wrong with:

du -B 1 -s -0 * \
  | sort -nz \
  | awk -v RS='\0' '{print $2}' \
  | xargs -d '\0' du -sh

?

Incidentally, instead of re-executing 'du' via xargs, I do this:

awk -v RS='\0' '{
  if ( $1 > 0x3F000000 )
    printf "%6.1fG\t", $1 / 0x40000000 ;
  else if ( $1 > 0xF0000 )
    printf "%6.1fM\t", $1 / 0x100000 ;
  else if ( $1 > 0x300 )
    printf "%6.1fK\t", $1 / 0x400 ;
  else
    printf "%6i\t", $1 ;
  $1="" ;
  print $0 ;
}'

...which has the advantage of being able to cope with a 'du -c' line (not to mention better alignment and less disk I/O).

--
Matthew
Please do not quote my e-mail address unobfuscated in message bodies.
--
"[Microsoft has] the deepest of pockets, unlimited ambition, and they are willing to lose money for years and years just to make sure that you don’t make any money, either." -- Robert Cringely




reply via email to

[Prev in Thread] Current Thread [Next in Thread]