{"id":1001,"date":"2013-01-24T05:02:39","date_gmt":"2013-01-24T11:02:39","guid":{"rendered":"http:\/\/blog.supportpro.com\/?p=1001"},"modified":"2026-01-08T03:52:57","modified_gmt":"2026-01-08T09:52:57","slug":"managing-linux-log-files-with-logrotate","status":"publish","type":"post","link":"https:\/\/www.supportpro.com\/blog\/managing-linux-log-files-with-logrotate\/","title":{"rendered":"How to Manage Linux Log file with Logrotate ?"},"content":{"rendered":"\n<div class=\"wp-block-group alignwide is-vertical is-layout-flex wp-container-core-group-is-layout-8cf370e7 wp-block-group-is-layout-flex\">\n<p>Log files play a critical role in Linux systems. They help administrators monitor system activity, troubleshoot issues, track application behavior, and maintain security. As systems run continuously, log files can grow very large over time. If left unmanaged, this can consume disk space and affect system performance.<\/p>\n\n\n\n<p><strong>Logrotate<\/strong> is a log file management utility designed to solve this problem. It automatically rotates, archives, compresses, and removes old log files, ensuring that logs remain manageable while preserving important historical data. Log rotation can be based on file size, age, or time intervals, and it is usually handled automatically through cron jobs or systemd timers.<\/p>\n\n\n\n<p>The main purpose of log rotation is simple: <strong>to prevent log files from growing indefinitely<\/strong> while keeping the system clean and efficient.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Logrotate Works<\/h2>\n\n\n\n<p>Logrotate periodically checks configured log files and applies defined rules when certain conditions are met, such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A log file reaching a specific size<\/li>\n\n\n\n<li>A log file being older than a defined time period<\/li>\n\n\n\n<li>A scheduled daily, weekly, or monthly rotation<\/li>\n<\/ul>\n\n\n\n<p>When rotation occurs, the existing log file is archived, optionally compressed, and a new log file is created for continued logging.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Logrotate Configuration Files<\/h2>\n\n\n\n<p>The primary configuration file for logrotate is<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/etc\/logrotate.conf<\/code><\/pre>\n\n\n\n<p>This file contains global settings that apply system-wide.<\/p>\n\n\n\n<p>In addition, individual applications and services typically have their own configuration files stored in:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/etc\/logrotate.d\/<\/code><\/pre>\n\n\n\n<p>Each file in this directory defines rotation rules specific to a service, such as Apache, MySQL, or system logs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Logrotate Options<\/h2>\n\n\n\n<p>Below are some commonly used logrotate options and their purposes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>compress<\/strong><br>Compresses rotated log files using gzip<\/li>\n\n\n\n<li><strong>nocompress<\/strong><br>Disables compression for rotated logs<\/li>\n\n\n\n<li><strong>copytruncate<\/strong><br>Copies the active log file and truncates the original file while the application continues writing to it<\/li>\n\n\n\n<li><strong>nocopytruncate<\/strong><br>Disables the copy-and-truncate behavior<\/li>\n\n\n\n<li><strong>create mode owner group<\/strong><br>Creates a new log file after rotation with specified permissions, owner, and group<\/li>\n\n\n\n<li><strong>nocreate<\/strong><br>Prevents logrotate from creating a new log file<\/li>\n\n\n\n<li><strong>delaycompress<\/strong><br>Delays compression until the next rotation cycle<\/li>\n\n\n\n<li><strong>nodelaycompress<\/strong><br>Compresses logs immediately after rotation<\/li>\n\n\n\n<li><strong>errors address<\/strong><br>Sends logrotate error messages to the specified email address<\/li>\n\n\n\n<li><strong>ifempty<\/strong><br>Rotates the log file even if it is empty (default behavior)<\/li>\n\n\n\n<li><strong>notifempty<\/strong><br>Skips rotation if the log file is empty<\/li>\n\n\n\n<li><strong>mail address<\/strong><br>Emails rotated log files to the specified address and removes them from the system<\/li>\n\n\n\n<li><strong>daily<\/strong><br>Rotates log files daily<\/li>\n\n\n\n<li><strong>weekly<\/strong><br>Rotates log files weekly<\/li>\n\n\n\n<li><strong>monthly<\/strong><br>Rotates log files monthly<\/li>\n\n\n\n<li><strong>rotate count<\/strong><br>Specifies how many rotated log files are kept before older ones are removed<\/li>\n\n\n\n<li><strong>size size<\/strong><br>Rotates the log file once it reaches the specified size<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Running Logrotate<\/h2>\n\n\n\n<p>Logrotate is usually executed automatically on most Linux systems. The typical workflow includes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Identifying log files that need to be managed<\/li>\n\n\n\n<li>Defining rotation rules and schedules for those log files<\/li>\n\n\n\n<li>Allowing logrotate to run automatically via cron or systemd timers<\/li>\n<\/ol>\n\n\n\n<p>A common cron-based execution looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/sbin\/logrotate \/etc\/logrotate.conf<\/code><\/pre>\n\n\n\n<p>This command is usually triggered by a system-managed cron job, such as <code>\/etc\/cron.daily\/logrotate<\/code>, and does not require manual intervention.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>Logrotate is an essential tool for maintaining healthy Linux systems. By automatically managing log file growth, it helps conserve disk space, improves performance, and ensures important log data remains accessible. Proper log rotation is a best practice for any production server or Linux environment.<\/p>\n\n\n\n<p>If you require help, <a href=\"https:\/\/www.supportpro.com\/requestquote.php\">contact SupportPRO Server Admin<\/a><\/p>\n<\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/www.supportpro.com\/freecheckup.php\"><img decoding=\"async\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/2725694\/9d590242-d641-4383-94b4-8cfd62f0af6b.png\" alt=\"Server not running properly? Get A FREE Server Checkup By Expert Server Admins - $125 Value\"\/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Log files play a critical role in Linux systems. They help administrators monitor system activity, troubleshoot issues, track application behavior, and maintain security. As systems run continuously, log files can&hellip;<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-1001","post","type-post","status-publish","format-standard","hentry","category-linux-basics"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1001","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/comments?post=1001"}],"version-history":[{"count":18,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1001\/revisions"}],"predecessor-version":[{"id":15109,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1001\/revisions\/15109"}],"wp:attachment":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/media?parent=1001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/categories?post=1001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/tags?post=1001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}