I have the following command to delete files in a folder that are 15 days or older:

find /var/www/App/app/var/sessions* -mtime +15 -exec rm {} \;

what is the best way to speed this up and run it on the background? I heard rm is a pretty slow operation


You can reduce the I/O priority of the operation. And you should not start one rm instance per file:

find /var/www/App/app/var/sessions* -mtime +15 -exec ionice -c3 rm {} +
|improve this answer|||||

Most modern versions of find support -delete as a parameter, so you won't be launching any more processes; just use that instead of the -exec string. Running it under ionice as well won't let it tie up the hard drive.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.