To many admins, logfiles are very handy, however sometimes they tend to get bigger and bigger, thus taking up a lot of space on your drive(s). The usual way to deal with such a problem is logrotation, implemented in many unix systems today.
There are, however, some commercial and non-commercial (open source) products which do produce logfiles, but do not (yet) have the ability to do logrotation. Of course one could easily do something like this to deal with the situation:
# rm logfile
# touch logfile
This method however, can present some problems with certain types of software. Too many times I have noticed that some software programs just stop writing to the logfile when it is removed, even when a new logfile has been created under the same permissions and ownerships. A restart of the software is often needed, and in production environments, this can cause serious problems!
For instance, a certain internet radiostation used the shoutcast server software to stream their live feed to their listeners. Unfortunately, when the shoutcast server log was deleted, logging was disabled, and the only way to get it back was to restart the server software, causing hundreds of listeners to have to reconnect to their favorite radiostation. Not good.
There is a solution though, which can be done in two ways. With the cat command, one can write something to a file without having to delete it.
So, in order to zero out a file, just do:
# cat /dev/null > logfile
and the second method is the same, but shorter:
# > logfile
This way your file is not deleted, just ‘nulled’, causing your badly written software not to choke on a sudden ‘missing’ file.
Cheers !
Rick