Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Onliner magic to remove files

by Anonymous Monk
on Dec 24, 2014 at 01:14 UTC ( [id://1111262]=note: print w/replies, xml ) Need Help??


in reply to Onliner magic to remove files

for(<*>){((stat)[9]<(unlink))}

The apparently useless stat and < made me a bit curious, so I googled it a bit. There are several places where the above is presented as a one-liner for "fast file deletion", but without explaining what the stat might be for.

Several people claimed that the Perl solution is faster than find with the -delete option, and I found one (possibly dubious) claim that it's because find uses fstatat64 syscalls while Perl uses lstat64+stat64 syscalls (a quick check on my system appears to confirm this). However, since it isn't my area of expertise, I'm not sure if that causes a speed difference.

In a post by Kent Fredric - https://www.quora.com/Linux-why-stat+unlink-can-be-faster-than-a-single-unlink - he shows that removing the stat actually gives a minor performance improvement, so I suspect it really isn't necessary.

My best guess for now is that the code snippet is a bastardization of something like this, and it's just been cargo-culted from there.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found