3 ms·
This Perl beats rsync by quite a margin here. perl -e 'opendir D, "."; @f = grep {$_ ne "." && $_ ne ".."} readdir D; unlink(@f) == $#f + 1 or die'
by ralph 13y ago
This Perl beats rsync by quite a margin here.
perl -e 'opendir D, "."; @f = grep {$_ ne "." && $_ ne ".."} readdir D;
unlink(@f) == $#f + 1 or die'
It goes a bit quicker still if @f and the error handling are omitted.
The original article is comparing different things some of the time, e.g. find is having to stat(2) everything to test if it's a file.
- psutor 13y agoI use perl for this as well. perl -e 'chdir "/var/session" or die; opendir D, "."; while ($f = readdir D) { unlink $f }' It is very efficient memory-wise compared to the other options as well as being much faster. It is also easy to apply filters as you would with -mtime or such in find, just change the end statement to: { if (-M $f > 30) {unlink $f} } to affect files modified more than 30 days ago.
- ralph 13y agoIt's not that I'd use Perl for the task, just that I don't think rsync is special. Indeed, rsync has the overhead of forking a child and communicating empty/'s bareness.