How can I delete old log files?
I'm trying to figure out how can I delete old log files, I'm using Centos 6.5 and in my /var/log
I see these old log files
messages
messages-20150802
messages-20150802
also the same in the /var/log/httpd
directory
access_log
access_log-20150802
access_log-20150809
access_log-20150816
access_log-20150823
I need to delete the older files that end with numeric values but keep the main once. what command could I use to do this.
Thanks in advanced
You can just use this commands:
rm -f messages-*
rm -f access_log-*
It will delete all old logs which starts with "messages-" and "access_log-"
take a look at logrotate and /etc/logrotate.conf.
Typically for log files you want to use the built in command rather then just deleting.
The logs with numbers have been rotated, best thing to do then is to compress each rotated log and have a script or cron to move those off the server and onto some persistent file store, for example, s3.
If you don't really care about preserving logs for whatever reason, you can always rm someRotatedLog.log.000
and then echo "" > someCurrentLog.log
so that the process logging to the file doesn't crash. But I recommend the first option way more.