This is to be run from a unix shell. It shows how to use perl as a filter, relying on unix tools for everything else.
find / -name "*.gz" | xargs ls -l | \ perl -ane 'print "$F[8]\n"if ($F[4]>1000000)' | \ xargs -pixxx rm xxx
  • Comment on search disk and prompt for deletion of files larger than a certain size
  • Download Code

Replies are listed 'Best First'.
RE: search disk and prompt for deletion of files larger than a certain size
by merlyn (Sage) on Oct 01, 2000 at 15:05 UTC
    We had a find ... xargs vs. File::Find discussion here before. Your entire program can be written by find2perl in a much more secure and efficient manner:
    find2perl /top/dir -name '*.gz' -eval 'size > 1000000 and unlink' | pe +rl

    -- Randal L. Schwartz, Perl hacker

RE: search disk and prompt for deletion of files larger than a certain size
by fundflow (Chaplain) on Oct 01, 2000 at 17:32 UTC
    merlyn gave a perl solution and here is a complete shell solution:
    find / -name '*.gz' -size +1000k -print | xargs rm -i
    or
    find / -name '*.gz' -size +1000k -print | xargs -p -n 1 rm
        The GNU versions can handle the "whitespace in the directory name" problems: find / -name '*.gz' -size +1000k -print0 | xargs -0 rm -i or find / -name '*.gz' -size +1000k -print0 | xargs -0 -p -n 1 rm Note the -print0 switch on the find and the -0 switch on the xargs command.
        Since you brought this point up more than once, i'm just wondering where are typical settings where you see spaces in filenames?

        (it is so rare for me that i usually just don't think about it)
        thanks,

        ff
RE: search disk and prompt for deletion of files larger than a certain size
by OzzyOsbourne (Chaplain) on Oct 03, 2000 at 22:06 UTC