Script to find largest files

Script to find largest files

am 01.11.2007 15:15:13 von groups.user

Hi Script Gurus..

i'm looking for a script to find the largest files in a filesystem,
ordered by size.

Does anyone have a similar script out there which they can share ?

Thanks

Re: Script to find largest files

am 01.11.2007 16:19:51 von jurgenex

groups.user@gmail.com wrote:
> Hi Script Gurus..

Hi Groups

> i'm looking for a script to find the largest files in a filesystem,
> ordered by size.

Reading these should get you started:
perldoc File::Find
perldoc -f -s
perldoc -f sort

jue

Re: Script to find largest files

am 01.11.2007 23:44:51 von Tad McClellan

groups.user@gmail.com wrote:


> i'm looking for a script


Then you are in the wrong place. Try a search engine.

This is the place to post if you want to *write* a script.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

Re: Script to find largest files

am 02.11.2007 15:05:15 von bugbear

groups.user@gmail.com wrote:
> Hi Script Gurus..
>
> i'm looking for a script to find the largest files in a filesystem,
> ordered by size.
>

du -s /* | sort -rn

HTH

BugBear

Re: Script to find largest files

am 02.11.2007 23:28:08 von hjp-usenet2

On 2007-11-02 14:05, bugbear wrote:
> groups.user@gmail.com wrote:
>> i'm looking for a script to find the largest files in a filesystem,
>> ordered by size.
>>
>
> du -s /* | sort -rn

man du

hp


--
_ | Peter J. Holzer | It took a genius to create [TeX],
|_|_) | Sysadmin WSR | and it takes a genius to maintain it.
| | | hjp@hjp.at | That's not engineering, that's art.
__/ | http://www.hjp.at/ | -- David Kastrup in comp.text.tex

Re: Script to find largest files

am 03.11.2007 10:42:21 von Martijn Lievaart

On Fri, 02 Nov 2007 14:05:15 +0000, bugbear wrote:

> groups.user@gmail.com wrote:
>> Hi Script Gurus..
>>
>> i'm looking for a script to find the largest files in a filesystem,
>> ordered by size.
>>
>>
> du -s /* | sort -rn

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

M4

Re: Script to find largest files

am 03.11.2007 12:39:41 von hjp-usenet2

On 2007-11-03 09:42, Martijn Lievaart wrote:
> On Fri, 02 Nov 2007 14:05:15 +0000, bugbear wrote:
>
>> groups.user@gmail.com wrote:
>>> i'm looking for a script to find the largest files in a filesystem,
>>> ordered by size.
>>>
>>>
>> du -s /* | sort -rn
>
> 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::prune = 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

--
_ | Peter J. Holzer | It took a genius to create [TeX],
|_|_) | Sysadmin WSR | and it takes a genius to maintain it.
| | | hjp@hjp.at | That's not engineering, that's art.
__/ | http://www.hjp.at/ | -- David Kastrup in comp.text.tex