Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a few virtualhosts set up on my machine, and the server keeps crashing because of the disk space being too full. I've checked out and it seems that one of my virtual host log folder is 2Gb. In it there are hundreds of log files, either gzipped or not.

My question is, is there an easy way to delete all that without deleting the current logs being used? Also, while at it, is there a way to tell the server to keep say 5 logs files at all time and delete the others?

Server is Debian.

thanks for your help

share|improve this question
    
Why don't you just use logrotate? –  Michael Hampton Aug 27 '13 at 2:27
    
Debain ships with logrotate. –  jscott Aug 27 '13 at 2:27
    
Coz I didn't know it was available, and not sure how to use it. Now how can I delete all these files that are already there? –  Got The Fever Media Aug 27 '13 at 2:31
    
And I see that logrotate would restart the server every night? Is that true? –  Got The Fever Media Aug 27 '13 at 2:38

1 Answer 1

up vote 0 down vote accepted

take a look for logrotate , you have many tutorial available on Internet, a quick search on Google and I found this tutorial.

Logrotate run every day with cron.daily, the script read /etc/logrotate.conf , this file contain all default configuration. Logrotate read other file in the directory /etc/logrotate.d.

So you can perform log rotation every day and keep only 5 day, to set this configuration you must define , in the file /etc/logrotate.conf:

# see "man logrotate" for details
# rotate log files weekly
daily
# keep 5 days worth of backlogs
rotate 5

You can add the option compress to compress rotated files. Take a look in files under /etc/logrotate.d to be sure your configuration is not overwrite.

you can do many things with logrotate take few time to read the documentation.

share|improve this answer

Your Answer

 
discard

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.