Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Script to find largest files

Reply
Thread Tools

Script to find largest files

 
 
groups.user@gmail.com
Guest
Posts: n/a
 
      11-01-2007
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

 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      11-01-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      11-01-2007
(E-Mail Removed) <(E-Mail Removed)> 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/"
 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      11-02-2007
On 2007-11-02 14:05, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
> (E-Mail Removed) 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.
| | | (E-Mail Removed) | That's not engineering, that's art.
__/ | http://www.hjp.at/ | -- David Kastrup in comp.text.tex
 
Reply With Quote
 
Martijn Lievaart
Guest
Posts: n/a
 
      11-03-2007
On Fri, 02 Nov 2007 14:05:15 +0000, bugbear wrote:

> (E-Mail Removed) 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
 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      11-03-2007
On 2007-11-03 09:42, Martijn Lievaart <(E-Mail Removed)> wrote:
> On Fri, 02 Nov 2007 14:05:15 +0000, bugbear wrote:
>
>> (E-Mail Removed) 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: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

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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I find the <TABLE> tag with the largest height and width RashmiRaju HTML 0 02-29-2008 06:31 PM
find largest frame Jack Javascript 7 10-26-2007 10:18 AM
Worlds Largest Photo and Worlds Largest Camera... Somebody Digital Photography 1 08-16-2007 02:51 AM
Algorithm to find nth largest or nth smallest in a range Code4u C++ 4 07-13-2005 03:18 AM
where I can find largest Standard C++ library list? PHP2 C++ 2 04-29-2004 01:11 AM



Advertisments