• 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. bootctl Command Examples (Control EFI firmware boot settings and manage boot loader)
  2. http-server-upload Command Examples
  3. acpi: command not found
  4. Creating and Removing Files and Directories Under Linux
  5. e2image Command Examples in Linux
  6. lxterminal Command Examples in Linux
  7. cut Command Examples in Linux
  8. How to use “yum downloadonly” to download a package without installing it
  9. Linux: No space left on device while df command shows a lot of free space
  10. pwd Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright