Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I assume this is relatively easy but my shell scripting isn't that great so I'm hoping to get some help.

I have a task which runs every hour and appends its output to a log file. I'd like to move that log file every night so that the script has an empty one to work with and the logs are easier to look at when I need to check them.

So I'd like a script which moves



/var/log/my.log.2 or or something.

How can I do that pretty easily?

share|improve this question
up vote 2 down vote accepted

You'll want to check out logrotate which is installed by default (or easily though a package manager) on nearly every major Linux distribution. It's quite easy to put together a simple configuration entry to rotate your log file -- everything you need to know about configuration options is on that man page.

Some distributions use a special /etc/logrorate.d/ directory to specify individual logrotate files for each log file (or a related group of log files). If your distribution uses this method, it's as simple as creating an appropriately-named file in that directory with a configuration block as described in the man page.

Otherwise you can simply just append your new configuration block to the end of the existing /etc/logrotate.conf file.

share|improve this answer
after I create the file in /etc/logrotate.d, will it run by default or do I need to set anything else up? – Matt Feb 8 '12 at 4:02
Logrotate runs in a daily cron and re-reads configuration files for each run, so there's no need to take additional steps. – Garrett Feb 8 '12 at 6:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.