| Hot: |
Like all Unix file systems, open log files can cause a real problem when they get too large and need to be deleted. The problem is, if you delete an open file, the link is removed, but all of the inodes are lost. Even worse, if the program continues to log to the file, the link never re-appears, and additional inodes are lost and are unrecoverable. I suggest two solutions to the above problems.
If you have lost inodes, a simple reboot (make sure FSCK is run on startup) will recover lost inodes and missing filespace.
To empty (or zero out) an open log file, simply issue the following command:
date > logfile
This will 'empty' the file and insert as the first line the output from the date command. If you want a completely empty file, don't enter date,
just > logfile.
This works great on apache and other web server logs, without ever stopping the service.
related post
<< 7 Examples for Sed Hold and Pattern Buffer Operations Finding all numbers that are bigger than 1 in vim >>
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
One Trackback/Ping
-
Dec 25 2009 at 10pm:
[...] posted here: Initialization or clearing of log files – Amit Agarwal By admin | category: zero command | tags: fact, file, from-the-date, issue-the-following, [...]








Facebook
Digg
Delicious
Flickr
FriendFeed
LinkedIn
MyBlogLog
Orkut
Reddit
StumbleUpon
Technorati
Twitter
Youtube






