Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 have a file called 'log.txt' that I would like to move to the logs folder on a nightly basis.

The problem is that I want to keep track of the files so I would actually need to move it to a log1.txt, log2.txt, log3.txt and so on.

Is there a unix command or a bash script way to do this?


share|improve this question
up vote 6 down vote accepted

You want to look at a tool called logrotate. You probably already have this installed due to other tools using it for exactly this purpose. It involves you writing a small config file and it will deal with rotating your logfile and restarting any process that has the file open.

share|improve this answer
Awesome! Thanks! – GeoffreyF67 Oct 19 '09 at 17:51

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.