I have some directories on our production servers which I want to delete. However last time I deleted them they caused connections to the servers to start timing out as the disk IO was being swamped. Is there a command I can use to slowly delete these directories or should I write myself a shell script with some liberal sleeps?


If sleep on your system returns 0 then you can just stick it in a find command:

find ... -exec sleep 1 \; -delete
| improve this answer | |
  • I thought about that but there are enough files that it would take at least a day at that speed. – Rory Hart Feb 21 '11 at 0:19
  • 4
    GNU sleep can take fractional delays, i.e. sleep 0.05. – Ignacio Vazquez-Abrams Feb 21 '11 at 0:23
  • You know that makes complete sense and I don't know why I assumed it didn't handle fractions! I'll blame it on Monday morning. Thanks. – Rory Hart Feb 21 '11 at 0:27
  • The command I used find . -depth -delete -print -exec sleep 0.05 \; – Rory Hart Feb 21 '11 at 0:36

Here is alternative

find . -type f -print0 | xargs -n 5 -0 -I {} rm {}; sleep 10

change parameters

-n 5 # this is how many files at the same time will be passed to rm command.


sleep 10 # this is how long in seconds will command sleep before next rm chunk is executed

| improve this answer | |

How about:

ls | xargs -I {} -n 1 sh -c 'echo {} ; sleep 1'

Just replace echo with rm and you should be good.

| 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.