• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

logrotate Command Examples in Linux

by admin

Log files keep track of events on the system. They are essential for debugging problems and monitoring live machines. Log files grow as time passes and more events are recorded. Since the older data is less useful than the current data, log files are renamed when they reach a size limit and the oldest files are deleted.

The logrotate tool allows you to rotate the logs that are generated by applications and scripts. It keeps your log directories clutter-free and minimizes disk usage when correctly configured. logrotate is installed by default, but if it is not installed, you can install it by running the below command:

# yum install -y logrotate

logrotate Command Options

Option Description
-d, –debug Turns on debug mode and implies -v.
-f, –force Tells logrotate to force the rotation, even if it doesn’t think this is necessary.
-m, –mail [command] Tells logrotate which command to use when mailing logs.
-s, –state Tells logrotate to use an alternate state file.
–usage Prints a short usage message.
–?, –help -Prints help message.
-v, –verbose Turns on verbose mode.

logrotate Command Examples

1. To force the log rotation:

# logrotate -f /etc/logrotate.conf
# logrotate --force /etc/logrotate.conf 

2. To test the log rotation:

# logrotate -d /etc/logrotate.conf
# logrotate --debug /etc/logrotate.conf 

3. To set to verbose mode:

# logrotate -v /etc/logrotate.conf
# logrotate --verbose /etc/logrotate.conf 

4. To get the help for logrotate:

# logrotate -?
# logrotate --help 

5. To display the brief usage help:

# logrotate --usage 

Final Thoughts

The logrotate tool is a script that is launched by cron everyday. The directives added to the default logrotate definition are compressed, daily, delaycompress, dateext, missingok, and rotate.

Filed Under: Linux

Some more articles you might also be interested in …

  1. firejail Command Examples in Linux
  2. Linux OS Service ‘cpuspeed’
  3. ceph: command not found
  4. “git log” Command Examples
  5. Downgrading an rpm package to a lower version (using “rpm” command)
  6. a2disconf Command Examples in Linux
  7. ack – A search tool like grep, optimized for developers (Command Examples)
  8. How to set up the htaccess File on Apache on CentOS/RHEL
  9. lvremove Command Examples in Linux
  10. How to grow/extend XFS filesytem in CentOS / RHEL using “xfs_growfs” command

You May Also Like

Primary Sidebar

Recent Posts

  • glab Command Examples
  • “glab repo” Command Examples
  • “glab release” Command Examples
  • “glab pipeline” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright