How to reallocate the deleted logfile space?

Hi All,

I know this is a simple question but i am not sure the exact answer it.

Here is the question:
There is a huge log file , if we delete the log file ,how the corresponding occupied file memory relocate to Hard Disk.

Thanks
Srinivas

Make sure there's no application/program that keeps the log file open even though it's deleted.
To release the disk space, don't delete the file but rewrite it with zero size.

Yes, after you have deleted the file there is little you can do to recover the allocated space apart from killing and restarting the process(es) that have the file open.

As RudiC points out you are better off writing zero size to the logfile eg:

# truncate -s0 /var/log/httpd/access_log

Or

# :> /var/log/httpd/access_log

As a long-term solution you should consider using the logrotate daemon to keep your logfile sizes down.

And don't be surprised if that doesn't work.

There are ways for applications to write to log files that create problems with that method. One of them is redirecting stderr/stdout by using ">>" shell redirection.

If those methods are used, filesystem-specific features can come into play.

There's a reason why operating systems provide robust, scalable logging facilities. Scalable logging is not something that can be done reliably without serious work.

So if your app is not well-designed, you may be stuck with "kill the app, clean up the log file, restart the app".