#!/usr/bin/perl -- use strict; use warnings; use File::Find::Rule; use Number::Bytes::Human qw(format_bytes); my $nBiggest = 20; my $progress = 1; Main( @ARGV ); exit( 0 ); sub Main { my @dirs = @_; push @dirs, '.' unless @dirs; # cwd my $rule = File::Find::Rule->file->readable; $rule->exec(\&progress) if $progress; my @files = $rule->in( @dirs ); @files = sort { $$b[0] <=> $$a[0] } map { [ -s $_ , $_ ] } @files; @files = @files[ 0 .. $nBiggest ]; print "\rBiggest $nBiggest\n"; for my $file ( @files ){ printf " %10s %s\n", format_bytes( $$file[0] ), $$file[1]; } } BEGIN { my $n = 0; my @s = qw[ * - \ | / ]; sub progress { local $|=1; print "\r", $s[ $n++ % 4 ]; 1; } } __END__ Biggest 20 282K blort.1.0.1.0.zip 104K blort.615.dll 104K blib/arch/auto/win32/blort/blort.dll 103K blort.cpp 100K blort.316.pll 100K blort.522.dll 54K win32-blort.tar.gz 49K x86/win32-blort.tar.gz 45K main.cpp 22K list.cpp 21K blort.pm 21K blib/lib/win32/blort.pm 20K fort.h 15K blib/html/lib/site/blort/blort.html 13K plfort.h 13K plfort.cpp 12K makefile 5.9K fort.cpp 4.6K rambo.diff 4.1K list.h 3.2K flap.cpp

In reply to Re: Find the n biggest files by Anonymous Monk
in thread Find the n biggest files by LinuxMatt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.