Script to find largest files

Discussion in 'Perl Misc' started by groups.user@gmail.com, Nov 1, 2007.

  1. Guest

    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
    , Nov 1, 2007
    #1
    1. Advertising

  2. 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
    Jürgen Exner, Nov 1, 2007
    #2
    1. Advertising

  3. <> 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/"
    Tad McClellan, Nov 1, 2007
    #3
  4. On 2007-11-02 14:05, bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
    > 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.
    | | | | That's not engineering, that's art.
    __/ | http://www.hjp.at/ | -- David Kastrup in comp.text.tex
    Peter J. Holzer, Nov 2, 2007
    #4
  5. On Fri, 02 Nov 2007 14:05:15 +0000, bugbear wrote:

    > 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
    Martijn Lievaart, Nov 3, 2007
    #5
  6. On 2007-11-03 09:42, Martijn Lievaart <> wrote:
    > On Fri, 02 Nov 2007 14:05:15 +0000, bugbear wrote:
    >
    >> 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.
    | | | | That's not engineering, that's art.
    __/ | http://www.hjp.at/ | -- David Kastrup in comp.text.tex
    Peter J. Holzer, Nov 3, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sanitarium
    Replies:
    2
    Views:
    542
    Whitecrest
    Dec 4, 2003
  2. PHP2
    Replies:
    2
    Views:
    408
    ¾ç¼¼ÈÆ
    Apr 29, 2004
  3. Code4u
    Replies:
    4
    Views:
    2,644
    Stephen Howe
    Jul 13, 2005
  4. RashmiRaju
    Replies:
    0
    Views:
    339
    RashmiRaju
    Feb 29, 2008
  5. Jack

    find largest frame

    Jack, Oct 19, 2007, in forum: Javascript
    Replies:
    7
    Views:
    147
Loading...

Share This Page