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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. CentOS / RHEL : How to collect sosreport
  2. How to Run a Script When USB Devices Is Attached or Removed Using UDEV
  3. CentOS / RHEL : How to find the creation time of LVM volume
  4. How to change the default permissions on /var/log/audit/audit.log file in CentOS/RHEL
  5. How to Schedule Jobs with ‘at’ command under Linux
  6. ‘ulimit: max user processes: cannot modify limit:operation not permitted’ Shown When Login
  7. “-bash: firewall: command not found” – How to resolve in CentOS/RHEL 7
  8. System Log File /var/log/messages Is Getting Deleted or Trimmed Automatically (CentOS/RHEL)
  9. Wallch (Wallpaper Changer) – Rotate Ubuntu Desktop Wallpapers
  10. Configuring sudo to Enable Commands for Non-Root Users in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • grpck command – Remove corrupt or duplicate entries in the /etc/group and /etc/gshadow files.
  • xxd command – Expressed in hexadecimal form
  • sesearch: command not found
  • macof: command not found

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright