How to delete/purge large log files in Solaris/Linux without restarting service

In Windows we cannot delete log files which are still being used by a service, for example Oracle related services (though there are many third-party tools which can do but we are talking in general).

In Solaris/Linux, we can rename the files but sometimes you will see that the new log entries are coming into the same old file which was renamed.

 

There is a simple way to clear the contents of a log file which is still being written by another service.

Take a backup of existing file if required for later reference. (Optional)

cp -p filename filename.bkp

Now empty the contents of the file without deleting or changing the inode.

> filename

(simply enter greater than sign followed by file name on command prompt)

 

You will see that the file size has become zero now and new logs will continue to fill this same file only.

No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>