How to add a file to logrotate on Linux

If you have a log file that gets written to frequently, you will want to add it to logrotate so it doesn’t consume all of your disk space. Logrotate will rotate the log according to your specifications and delete old logs.

Tools:

  • 1 ea Linux

1Open /etc/logrotate.conf

Using your favorite editor (vim), edit /etc/logrotate.conf. vim /etc/logrotate.conf

2Add an entry for your log file

At the end of logrotate.conf, add the full path to your log file followed by open and close curly brackets. There are many options you can add like the frequency to rotate “daily/weekly/monthly” and the number of rotations to keep “rotate 2/rotate 3”. For a full list of options go to http://linuxcommand.org/man_pages/logrotate8.html. Each option gets added in between the curly brackets and on their own line.


Now learn about:


Discuss this guide

var disqus_shortname = ‘howchootest’; (function() { var dsq = document.createElement(‘script’); dsq.type = ‘text/javascript’; dsq.async = true; dsq.src = ‘//’ + disqus_shortname + ‘.disqus.com/embed.js’; (document.getElementsByTagName(‘head’)[0] || document.getElementsByTagName(‘body’)[0]).appendChild(dsq); })();

Tools:

  • 1 ea Linux

Leave a Reply

Your email address will not be published. Required fields are marked *