Initialization or clearing of log files

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.

7 Examples for Sed Hold and Pattern Buffer Operations



Image by pqs via Flickr

This article is part of the on-going Unix Sed Tips and Tricks series. In our previous sed articles we learned — sed printing, sed deletion, sed substitute , sed file write, sed multiple commands, sed multi-line operation, and sed manipulate file lines. In our first part of sed tutorial we learned that sed has two […]