Friday, November 14, 2008

How to Empty/Remove/Delete/Clear Log Files, etc. without Losing File Handles

When you want to clear/empty/remove/delete a log file without an application or library (like log4j, etc.) losing the file handle (as it is bad in production when the application can't log), just echo into the file (so that the file is never deleted, just cleared):
echo > filename.log
I learned that trick several years ago from Anders, and it seems this was new to one of our sysadmins at work, so I decided to share it.

No comments: