We routinely delete old log files. Why? Some of them are very large and take up valuable space on the hard drive. These old logs were generated by workstations/servers, web servers, databases, and many other ubiquitous applications.
Note: When I stated old log files, I meant terminated files--not ones with open file handles.
# cd /where_your_logs_are
# find . -name '*.deadlog' -exec rm {} \;
This blog covers Unix system administration HOWTO tips for using inline for loops, find command, Unix scripting, configuration, SQL, various Unix-based tools, and command line interface syntax. The Unix OS supports tasks such as running hardware, device drivers, peripherals and third party applications. Share tips/comments. Read the comments. But most importantly: Read Disclaimer - Read Disclaimer.
Subscribe to:
Post Comments (Atom)
3 comments:
The suggested command will usually not delete the log file, because the daemon which is logging to that file will still have an open file handle to it. The file will just be unlinked from its directory, rendering it invisible (along with any subsequent log messages).
Most daemons have a mechanism for requesting the log file be closed and re-opened, eg sending a SIGHUP signal to the daemon. Still it is not ideal to remove the most recent log messages... what about log rotation?
Luke,
Most of the logs we delete have been terminated by a daemon. In fact, some of our logs end with a *.dead extension or something else other than *.log. I should have been clearer about that. Thanks for adding your valuable comment.
Is there a way that the logs can be deleted in one command?
Post a Comment