Quoting Patrick O'Connor (patrick.oconnor at sysadmin.ie):
> 2010/1/19 Paul O'Malley - gnu's not unix - <ompaul at eircom.net>
>> > du -cks * | sort -rn
> >
>> That's one hell of an itch scratched! Having great fun trying it out on my
> boxen! (Sad I know)
Definitely has the benefit of being simple and easy to remember. Sometimes,
though, you want to know what are the largest _files_ in a tree. (The above
includes subdir byte counts.) Something like this will do:
#!/usr/bin/perl -w
use File::Find;
@ARGV = $ENV{ PWD } unless @ARGV;
find ( sub { $size{ $File::Find::name } = -s if -f; }, @ARGV );
@sorted = sort { $size{ $b } <=> $size{ $a } } keys %size;
splice @sorted, 20 if @sorted > 20;
printf "%10d %s\n", $size{$_}, $_ for @sorted
Or, equivalently:
find . -xdev -type f -print0 | xargs -r0 ls -l | sort -rn -k 5 | head -20
--
Rick Moen "Passive voice is used when the receiver of an
rick at linuxmafia.com action is more important than the performer. Ex:
Your mom was banged." -- FakeAPStylebook
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!