In general, we use rm command to delete files, shred command for secure deletion. But for Large files like 100s of GB files deletion can not be that easy as it uses more RAM and CPU while the process is running, which may increase the load on server and slow it down.
We can use ionice to define I/O scheduling class and priority for another process.
When we use ionice with command rm, it will run this command with given arguments.
# man ionice
OPTIONS -c, --class class Specify the name or number of the scheduling class to use; 0 for none, 1 for realtime, 2 for best-effort, 3 for idle. -n, --classdata level Specify the scheduling class data. This only has an effect if the class accepts an argument. For realtime and best- effort, 0-7 are valid data (priority levels). -p, --pid PID... Specify the process IDs of running processes for which to get or set the scheduling parameters. -t, --ignore Ignore failure to set the requested priority. If command was specified, run it even in case it was not possible to set the desired scheduling priority, which can happen due to insufficient privileges or an old kernel version. -h, --help Display help and exit. -V, --version Display version information and exit.
To specify the name or number of the scheduling class to use (0 for none, 1 for real time, 2 for best-effort, 3 for idle) the command below.
This means that rm will belong to idle I/O class and only uses I/O when any other process does not need it:
# ionice -c 3 rm /var/logs/maillog # ionice -c 3 rm -rf /var/log/apache/access_logs
If there won’t be much idle time on the system, then we may want to use scheduling class and set a low priority like this:
# ionice -c 2 -n 6 rm /var/logs/maillog # ionice -c 2 -n 6 rm -rf /var/log/apache/access_logs