Linux – Deleting very large file without webserver freezing

apache-2.2centoslinux

In my web server(apache is running, Linux CentOS),
there is a very large log file(50 Gbyte).
This web server have some web services in production.

When I tried to delete the log file,
web server had no response about 10 seconds.
(Service out time.)

rm -f monthly.log

Is there any way to delete this large file without apache freezing?

Best Answer

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