Find and delete old files in linux redux
After some lovely feedback from Sotiris Tsimbonis on my last post Find and delete old files in linux I have a better (faster) way to delete files.
Spawning processes is expensive, its much better to not spawn a new process if its not needed. Just for proof I created 100 empty files in a temp directory and deleted them both ways.
The old way …
for i in $(seq 100); do touch $i;done
time find ./ -type f -exec rm {} \;
real 0m0.273s
user 0m0.104s
sys 0m0.108s
The better faster way
for i in $(seq 100); do touch $i;done
time find ./ -type f -delete
real 0m0.009s
user 0m0.004s
sys 0m0.004s
And lets see the creation loop with xargs since we are talking about squeezing a tad more performance out of things.
The standard for loop …
time for i in $(seq 100); do touch $i;done
real 0m0.518s
user 0m0.248s
sys 0m0.200s
And the better faster xargs way
time seq 100 | xargs touch
real 0m0.028s
user 0m0.008s
sys 0m0.004s
Comments (No comments)
What do you think?