6

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

1
  • 1
    Take a look at your logrotate configuration (/etc/logrotate.d). You can configure additional things like compressing logs and straight up removing them.
    – Gene
    Aug 25, 2015 at 19:10

3 Answers 3

3

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-"

2

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.

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .