How to Setup and Manage Log Rotation Using Logrotate in Linux

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Gabriel Cánepa

Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

10 Responses

  1. Sarjit Singh says:

    How can I setup logrotate to rotate the logs hourly?
    There is no option and minimum frequency is daily.

  2. Siva says:

    Hi log rotate is not working, please help me.

    /opt/var/foo.log {
        rotate 3
        size 10M

    It is appending data on same file, now the file size reached 6GB how can I fix it

  3. Kumar P says:

    Hello Gabriel A. Cánepa,

    Are we allowed to add our own log path of apache2 here ? with new file on /etc/logrotate.d/mylog with my own log path ?

  4. youtube to mp3 says:

    So i wasn’t sure, if i already have logrotate and it seems like it takes care of logs in /var/log/ folder, all of them seem to be numbered, dated, and stuff, so i am assuming it’s on and working, but what about manually specified folders, for example, all of my websites have their logs in their special folders, and not in /var/log/. How do i go about this? will simple directive on holding those logs in /var/log take care of log-rotation as well? i mean, if i set my website to keep its log in /var/log, do i need to worry about rotation, or will everything in that folder auto-rotate if logrotate is installed?

    a bit confusing, but basically trying to go the way of least resistance… =)

  5. K Sinclair says:

    Hi, I am new to Linux and recently built a syslog server but the log file is not rotating. I have the entry below for the logrotate.conf file and the error I get when I try to force it to run using:

    # logrotate -vdf /etc/logrotate.conf

    Can you tell me what I need to change for the rotate to run properly.

    /var/log/Firewalls/firewall.log {
    rotate 30
    systemctl restart rsyslog

    (It’s world writable or writable by group which is not “root”) Set “su” directive in config file to tell logrotate which user/group should be used for rotation.

  6. fatboy92 says:

    Hi all,

    What about cases where the outdoor is never close. I had that case, it meant that the file ran full, i.e. the file system ran full, the file however showed only a small.size. A real problem when you don’t know. The file system says it’s full, but the sum of all file sizes is much smaller than the file system.

  7. Ravikumar says:

    How to rotate logs manually. If I want to rotate the log files now, what to do?

    • Gabriel A. Cánepa says:

      As explained in this very article, you can rotate the logs by using the same command as in the dry-run – just omit the -d option. Assuming you want to process the /var/log/squid/access.log file, do:
      logrotate /etc/logrotate.d/squid.conf

    • gasmyr says:

      logrotate -f myConfig_file, have a look in man page of logrotate(man logrotate)

Got something to say? Join the discussion.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.