I have a list of directories that I'd like to delete. However when I do them all at one, load spikes on the box. Does anyone have an example of a script that would wait until load was under a certain level before proceeding with the deletion (interation of the loop)
Better still, use
ionice
.This'll cause your delete command only to run when the disk IO is free, so it has the lowest priority. Cyberciti has a nice little article on all the variants you have, and how to use them.
ionice
is probably the best/simplest solution, but its only really delaying the inevitable and potentially just mean prolonged medium load versus a short run of high load.There is a good write up here http://www.depesz.com/2010/04/04/how-to-remove-backups/ on a systematic controlled approach.
Changing the io scheduler, removing journals, atime and diratime are also contributory factors. There is also a different deletion binary
fastrm
, you can find the man here http://linux.die.net/man/1/fastrmDon't try this at home
A while ago, we were testing faster deletion methods of deletion for terabytes of data. In the end it actually proved quicker to start a
rm
ormv
then interrupt the process with^c
. Then restart the machine with a forcedfsck
- which then would clean up the inodes and free up the subsequent space on the file system.It worked surprisingly well and far quicker than a traditional delete - but I would never ever do it on a production system. Ever.