Deleting very large file without webserver freezing
Solution 1:
Rotate it first via logrotate
, using a config like this:
/path/to/the/log {
missingok
notifempty
sharedscripts
daily
rotate 7
postrotate
/sbin/service httpd reload > /dev/null 2>/dev/null || true
endscript
compress
}
then create a cron job at midnight to delete the rotated file:
30 2 * * * nice -n 19 ionice -c2 -n7 rm -f /path/to/the/log/file.1
Solution 2:
For faster deletion of big files, you can use the truncate
command -
Say to shrink it to a size of zero and then delete it:
truncate -s 0 monthly.log && rm -f monthly.log
As quanta recommended, you need to logrotate it first though.
Solution 3:
echo "0" > monthly.log && rm -f monthly.log