Won't work, will not find hidden files. I normaly use (from memory):
find / -mindepth 1 -maxdepth 1 -print0 | xargs -0 du -s | sort -rn
Why are you all intent on using du? It does something completely
different:
% find / -mindepth 1 -maxdepth 1 -print0 | xargs -0 du -s | sort -rn
6882520 /home
2778612 /usr
1021384 /var
134588 /lib
26692 /boot
[...]
/home is not the largest file on my root filesystem. In fact it isn't on
my root filesystem at all.
The correct solution is:
find $mountpoint -xdev -printf "%s %p\n" | sort -rn
(-printf is an extension of GNU find, but so is -print0. You may also
throw a -type f in there if you are only interested in regular files)
Since this is a perl group, not a shell group, here's the equivalent
script in perl:
#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
my %files;
find(\&wanted, $ARGV[0]);
for (sort { $files{$b} <=> $files{$a} } keys %files) {
print "$files{$_} $_\n";
}
sub wanted {
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size) = lstat($_);
if ($dev != $File::Find::topdev) {
$File::Find:
rune = 1;
return;
}
$files{$File::Find::name} = $size;
}
__END__
Which is quite a bit larger but should be OS independent and even deals
correctly with filenames with embedded newlines.
hp