Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

search disk and prompt for deletion of files larger than a certain size

by gregorovius (Friar)
on Oct 01, 2000 at 11:25 UTC ( [id://34811]=CUFP: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://34811]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2024-04-24 14:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found