{"id":3480,"date":"2024-07-17T10:00:50","date_gmt":"2024-07-17T10:00:50","guid":{"rendered":"https:\/\/draculaservers.com\/tutorials\/?p=3480"},"modified":"2024-08-04T21:19:11","modified_gmt":"2024-08-04T21:19:11","slug":"logrotate-managing-log-files-in-linux","status":"publish","type":"post","link":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/","title":{"rendered":"Logrotate: Managing Log Files in Linux"},"content":{"rendered":"<div class=\"cl-preview-section\"><\/div>\n<div class=\"cl-preview-section\">\n<p>Logs are critical for diagnosing issues within applications and the overall system. They provide insights into system operations and help pinpoint problems. However, over time, logs can accumulate and grow large, potentially causing management headaches. This is where\u00a0<code>logrotate<\/code>\u00a0comes into play\u2014a powerful tool for managing and maintaining log files efficiently.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>In this guide, we\u2019ll explore how to use\u00a0<code>logrotate<\/code>\u00a0to keep your log files in check, ensuring they don\u2019t consume excessive disk space while providing you with valuable insights when needed.<\/p>\n\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"what-is-logrotate\">What is Logrotate?<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Logrotate is a Linux utility designed to handle log files. It performs several important tasks:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<ul>\n<li><strong>Rotation<\/strong>: It periodically renames and compresses old log files, creating new, empty log files.<\/li>\n<li><strong>Compression<\/strong>: It reduces the size of rotated logs by compressing them, saving disk space.<\/li>\n<li><strong>Removal<\/strong>: It deletes old log files after a specified number of rotations or based on age.<\/li>\n<li><strong>Execution<\/strong>: It can execute custom scripts before or after the rotation process.<\/li>\n<\/ul>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Logrotate is typically pre-installed on many Linux distributions, but if it\u2019s not available, it can be easily installed via your package manager.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"checking-the-installed-logrotate-version\"><span id=\"checking-the-installed-logrotate-version-2\">Checking the Installed Logrotate Version<\/span><\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To verify if\u00a0<code>logrotate<\/code>\u00a0is installed and check its version, use the following command:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\">logrotate --version\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This will display the installed version of\u00a0<code>logrotate<\/code>, confirming that it\u2019s ready for use.<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"locating-log-files\">Locating Log Files<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>By default, log files are stored in the\u00a0<code>\/var\/log<\/code>\u00a0directory. To view the contents of this directory, use:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">ls<\/span> \/var\/log\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This command lists all log files and directories, giving you an overview of the logs you need to manage.<\/p>\n<div class=\"cl-preview-section\">\n<h2 id=\"checking-the-installed-logrotate-version\">Checking the Installed Logrotate Version<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To verify if\u00a0<code>logrotate<\/code>\u00a0is installed and check its version, use the following command:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\">logrotate --version\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This will display the installed version of\u00a0<code>logrotate<\/code>, confirming that it\u2019s ready for use.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Certainly! Here\u2019s a detailed section on installing\u00a0<code>logrotate<\/code>\u00a0on Linux, tailored to your writing style:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<hr \/>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"installing-logrotate-on-linux\">Installing Logrotate on Linux<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><code>Logrotate<\/code>\u00a0is an essential utility for managing log files in Linux, ensuring they don\u2019t consume excessive disk space and remain organized. While many modern Linux distributions come with\u00a0<code>logrotate<\/code>\u00a0pre-installed, you might need to install it manually on some systems. Here\u2019s how you can install\u00a0<code>logrotate<\/code>\u00a0on various Linux distributions.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"ubuntu-and-debian-based-distributions\">Ubuntu and Debian-Based Distributions<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>On Ubuntu and other Debian-based distributions,\u00a0<code>logrotate<\/code>\u00a0is available from the default package repositories. To install it, follow these steps:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<ol>\n<li><strong>Update Package Index<\/strong>: Ensure your package index is up to date to get the latest version of\u00a0<code>logrotate<\/code>.\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sudo<\/span> apt update\r\n<\/code><\/pre>\n<\/li>\n<li><strong>Install Logrotate<\/strong>: Use the\u00a0<code>apt<\/code>\u00a0package manager to install\u00a0<code>logrotate<\/code>.\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sudo<\/span> apt <span class=\"token function\">install<\/span> logrotate\r\n<\/code><\/pre>\n<\/li>\n<li><strong>Verify Installation<\/strong>: Check that\u00a0<code>logrotate<\/code>\u00a0is installed and see its version with:\n<pre class=\" language-bash\"><code class=\"prism  language-bash\">logrotate --version\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"centos-and-red-hat-based-distributions\">CentOS and Red Hat-Based Distributions<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>For CentOS, Red Hat Enterprise Linux (RHEL), and other Red Hat-based distributions, you can install\u00a0<code>logrotate<\/code>\u00a0using\u00a0<code>yum<\/code>\u00a0or\u00a0<code>dnf<\/code>, depending on your version of the distribution.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<ol>\n<li><strong>Install Logrotate<\/strong>: Use the\u00a0<code>yum<\/code>\u00a0or\u00a0<code>dnf<\/code>\u00a0package manager to install\u00a0<code>logrotate<\/code>.\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sudo<\/span> yum <span class=\"token function\">install<\/span> logrotate\r\n<\/code><\/pre>\n<p>or for newer versions using\u00a0<code>dnf<\/code>:<\/p>\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sudo<\/span> dnf <span class=\"token function\">install<\/span> logrotate\r\n<\/code><\/pre>\n<\/li>\n<li><strong>Verify Installation<\/strong>: Confirm the installation and check the version:\n<pre class=\" language-bash\"><code class=\"prism  language-bash\">logrotate --version\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"fedora\">Fedora<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>On Fedora,\u00a0<code>logrotate<\/code>\u00a0is available through the\u00a0<code>dnf<\/code>\u00a0package manager.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<ol>\n<li><strong>Install Logrotate<\/strong>: Install\u00a0<code>logrotate<\/code>\u00a0using\u00a0<code>dnf<\/code>.\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sudo<\/span> dnf <span class=\"token function\">install<\/span> logrotate\r\n<\/code><\/pre>\n<\/li>\n<li><strong>Verify Installation<\/strong>: Check the installed version of\u00a0<code>logrotate<\/code>.\n<pre class=\" language-bash\"><code class=\"prism  language-bash\">logrotate --version\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"arch-linux-and-arch-based-distributions\">Arch Linux and Arch-Based Distributions<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>For Arch Linux and distributions based on Arch, such as Manjaro, use\u00a0<code>pacman<\/code>\u00a0to install\u00a0<code>logrotate<\/code>.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<ol>\n<li><strong>Install Logrotate<\/strong>: Use\u00a0<code>pacman<\/code>\u00a0to install\u00a0<code>logrotate<\/code>.\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sudo<\/span> pacman -S logrotate\r\n<\/code><\/pre>\n<\/li>\n<li><strong>Verify Installation<\/strong>: Confirm the installation by checking the version.\n<pre class=\" language-bash\"><code class=\"prism  language-bash\">logrotate --version\r\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"configuring-logrotate\">Configuring Logrotate<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The main configuration file for\u00a0<code>logrotate<\/code>\u00a0is located at\u00a0<code>\/etc\/logrotate.conf<\/code>. This file contains global settings and includes additional configuration files from\u00a0<code>\/etc\/logrotate.d\/<\/code>.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"configuration-directives\">Configuration Directives<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Here are some common directives used in\u00a0<code>logrotate<\/code>\u00a0configurations:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<ul>\n<li><strong><code>daily<\/code>\u00a0\/\u00a0<code>weekly<\/code>\u00a0\/\u00a0<code>monthly<\/code><\/strong>: Specifies the frequency of log rotation.<\/li>\n<li><strong><code>rotate N<\/code><\/strong>: Defines how many rotated log files to keep.<\/li>\n<li><strong><code>compress<\/code><\/strong>: Compresses old log files to save space.<\/li>\n<li><strong><code>delaycompress<\/code><\/strong>: Delays compression until the next rotation cycle.<\/li>\n<li><strong><code>notifempty<\/code><\/strong>: Avoids rotating empty log files.<\/li>\n<li><strong><code>missingok<\/code><\/strong>: Ignores errors if a log file is missing.<\/li>\n<li><strong><code>size SIZE<\/code><\/strong>: Rotates the log file when it reaches a specified size.<\/li>\n<li><strong><code>dateext<\/code><\/strong>: Adds a date extension to rotated log files.<\/li>\n<li><strong><code>copytruncate<\/code><\/strong>: Creates a copy of the log file and truncates the original file.<\/li>\n<li><strong><code>prerotate<\/code><\/strong>\u00a0and\u00a0<strong><code>postrotate<\/code><\/strong>: Executes scripts before and after rotation.<\/li>\n<\/ul>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"syntax\">Syntax<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The basic syntax for a\u00a0<code>logrotate<\/code>\u00a0command is:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\">logrotate <span class=\"token punctuation\">[<\/span>OPTION<span class=\"token punctuation\">]<\/span> config_file_path\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"practical-examples\">Practical Examples<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Let\u2019s dive into some practical examples to demonstrate how\u00a0<code>logrotate<\/code>\u00a0can be configured and used effectively.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"example-1-simple-logrotate-configuration\">Example 1: Simple Logrotate Configuration<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Create a log file named\u00a0<code>\/var\/log\/test.log<\/code>\u00a0with sample data. Then, create a new configuration file at\u00a0<code>\/etc\/tmp\/logrotate.conf<\/code>:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">nano<\/span> \/etc\/tmp\/logrotate.conf\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Add the following content to rotate the log file daily if it exceeds 5KB:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-plaintext\"><code class=\"prism  language-plaintext\">\/var\/log\/test.log {\r\n  daily\r\n  size 5K\r\n  su root adm\r\n}\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To check the size of the log file and perform rotation, use:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">ls<\/span> -l \/var\/log\/test.log\r\n<span class=\"token function\">sudo<\/span> logrotate \/etc\/tmp\/logrotate.conf\r\n<span class=\"token function\">ls<\/span> -l \/var\/log\/test.log\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>If the file size is less than 5KB, rotation will not occur. Adjust the size to 1KB to see rotation in action.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"example-2-using-copytruncate\">Example 2: Using Copytruncate<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To create a copy of the log file and truncate the original, modify the configuration file as follows:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-plaintext\"><code class=\"prism  language-plaintext\">\/var\/log\/test.log {\r\n  rotate 5\r\n  size 1K\r\n  copytruncate\r\n  su root adm\r\n}\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Run\u00a0<code>logrotate<\/code>\u00a0and check the file size to see the effect of\u00a0<code>copytruncate<\/code>:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sudo<\/span> logrotate \/etc\/tmp\/logrotate.conf\r\n<span class=\"token function\">ls<\/span> -l \/var\/log\/test.log\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>The original file should be truncated to 0 bytes, while the new file contains the log data.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"example-3-using-compression\">Example 3: Using Compression<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To compress old log files, update your configuration:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-plaintext\"><code class=\"prism  language-plaintext\">\/var\/log\/test.log {\r\n  rotate 5\r\n  size 1K\r\n  compress\r\n  create 770 root adm\r\n}\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>After running\u00a0<code>logrotate<\/code>, verify that a compressed file (e.g.,\u00a0<code>test.log.1.gz<\/code>) is created:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sudo<\/span> logrotate \/etc\/tmp\/logrotate.conf\r\n<span class=\"token function\">ls<\/span> \/var\/log\/\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<div class=\"cl-preview-section\">\n<h3 id=\"affordable-vps-hosting-with-dracula-servers\"><span style=\"color: #ff2600;\">Affordable VPS Hosting With Dracula Servers<\/span><\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Looking for reliable and budget-friendly Virtual Private Server (VPS) hosting? Look no further than\u00a0<a href=\"https:\/\/draculaservers.com\/\">Dracula Servers<\/a>. Dracula Servers offers a range of VPS hosting plans tailored to meet diverse needs. With competitive pricing, robust performance, and a user-friendly interface, it\u2019s an excellent choice for individuals and businesses alike.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Explore the\u00a0<a href=\"https:\/\/draculaservers.com\/\">Dracula Servers website<\/a> to discover hosting solutions that align with your requirements and take your online presence to new heights with their affordable and efficient VPS hosting services.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<p><a href=\"https:\/\/draculaservers.com\/\"><strong>Visit Dracula Servers<\/strong><\/a>\u00a0and experience reliable VPS hosting without breaking the bank.<\/p>\n<\/div>\n<h3 id=\"example-4-adding-date-extensions\">Example 4: Adding Date Extensions<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To include date extensions in the rotated files:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-plaintext\"><code class=\"prism  language-plaintext\">\/var\/log\/test.log {\r\n  su root adm\r\n  rotate 5\r\n  size 1K\r\n  compress\r\n  create 770 root adm\r\n  dateext\r\n}\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Check the file list to see rotated logs with date extensions:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sudo<\/span> logrotate \/etc\/tmp\/logrotate.conf\r\n<span class=\"token function\">ls<\/span> -l \/var\/log\/\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"example-5-using-maxage\">Example 5: Using Maxage<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To keep rotated logs for a specific number of days, configure:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-plaintext\"><code class=\"prism  language-plaintext\">\/var\/log\/test.log {\r\n  su root adm\r\n  rotate 5\r\n  size 1K\r\n  compress\r\n  maxage 1\r\n}\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>This setting will remove logs older than one day. Verify with:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">sudo<\/span> logrotate -s<span class=\"token operator\">=<\/span>\/var\/log\/out.log \/etc\/tmp\/logrotate.conf\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"example-6-handling-missing-logs\">Example 6: Handling Missing Logs<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>To avoid errors for missing logs, add\u00a0<code>missingok<\/code>:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-plaintext\"><code class=\"prism  language-plaintext\">\/var\/log\/testfile.log {\r\n  su root adm\r\n  rotate 5\r\n  size 1K\r\n  compress\r\n  missingok\r\n}\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>If the file doesn\u2019t exist,\u00a0<code>logrotate<\/code>\u00a0will proceed without errors.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h3 id=\"example-7-running-scripts-before-rotation\">Example 7: Running Scripts Before Rotation<\/h3>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Create a script (<code>\/home\/fahmida\/test.sh<\/code>) to run before log rotation:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token shebang important\">#!\/bin\/bash<\/span>\r\n<span class=\"token keyword\">echo<\/span> <span class=\"token string\">\"Logrotate example executed.\"<\/span>\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Make it executable:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-bash\"><code class=\"prism  language-bash\"><span class=\"token function\">chmod<\/span> a+x \/home\/fahmida\/test.sh\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Update the configuration:<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<pre class=\" language-plaintext\"><code class=\"prism  language-plaintext\">\/var\/log\/test.log {\r\n  su root adm\r\n  rotate 5\r\n  size 1K\r\n  prerotate\r\n  \/home\/fahmida\/test.sh\r\n  endscript\r\n}\r\n<\/code><\/pre>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>After executing\u00a0<code>logrotate<\/code>, check the output of the script.<\/p>\n<\/div>\n<div class=\"cl-preview-section\">\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<\/div>\n<div class=\"cl-preview-section\">\n<p>Logrotate is an essential tool for managing log files in Linux, providing flexibility and control over log file rotation, compression, and maintenance. By following the examples in this guide, you can tailor\u00a0<code>logrotate<\/code>\u00a0to fit your needs, ensuring that your log files are well-managed and that your system remains efficient and responsive.<\/p>\n<p>Check out More Linux Tutorials <a href=\"https:\/\/draculaservers.com\/tutorials\/\" target=\"_blank\" rel=\"noopener\">Here!<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Logs are critical for diagnosing issues within applications and the overall system. They provide insights into system operations and help pinpoint problems. However, over time, logs can accumulate and grow large, potentially causing management headaches. This is where\u00a0logrotate\u00a0comes into play\u2014a powerful tool for managing and maintaining log files efficiently. In this guide, we\u2019ll explore how [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":3481,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[605,604,603],"class_list":["post-3480","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-getting-started","tag-how-to-manage-log-files-with-logrotate","tag-how-to-use-logrotate-on-linux","tag-logrotate-on-linux"],"blocksy_meta":[],"featured_image_urls_v2":{"full":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46.png",1280,720,false],"thumbnail":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46-150x150.png",150,150,true],"medium":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46-300x169.png",300,169,true],"medium_large":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46-768x432.png",768,432,true],"large":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46-1024x576.png",1024,576,true],"1536x1536":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46.png",1280,720,false],"2048x2048":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46.png",1280,720,false],"pk-small":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46-80x80.png",80,80,true],"pk-thumbnail":["https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46-300x225.png",300,225,true]},"post_excerpt_stackable_v2":"<p>Logs are critical for diagnosing issues within applications and the overall system. They provide insights into system operations and help pinpoint problems. However, over time, logs can accumulate and grow large, potentially causing management headaches. This is where\u00a0logrotate\u00a0comes into play\u2014a powerful tool for managing and maintaining log files efficiently. In this guide, we\u2019ll explore how to use\u00a0logrotate\u00a0to keep your log files in check, ensuring they don\u2019t consume excessive disk space while providing you with valuable insights when needed. What is Logrotate? Logrotate is a Linux utility designed to handle log files. It performs several important tasks: Rotation: It periodically renames&hellip;<\/p>\n","category_list_v2":"<a href=\"https:\/\/draculaservers.com\/tutorials\/category\/getting-started\/\" rel=\"category tag\">Getting Started<\/a>","author_info_v2":{"name":"Abdul Mannan","url":"https:\/\/draculaservers.com\/tutorials\/author\/abdul-mannan-tbgmail-com\/"},"comments_num_v2":"0 comments","yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Logrotate: Managing Log Files in Linux - Dracula Servers Tutorials<\/title>\n<meta name=\"description\" content=\"Logrotate is a tool for managing log files in Linux, providing flexibility and control over log file rotation, compression, and maintenance\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Logrotate: Managing Log Files in Linux - Dracula Servers Tutorials\" \/>\n<meta property=\"og:description\" content=\"Logrotate is a tool for managing log files in Linux, providing flexibility and control over log file rotation, compression, and maintenance\" \/>\n<meta property=\"og:url\" content=\"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"Dracula Servers Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2024-07-17T10:00:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-04T21:19:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Abdul Mannan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Abdul Mannan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/logrotate-managing-log-files-in-linux\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/logrotate-managing-log-files-in-linux\\\/\"},\"author\":{\"name\":\"Abdul Mannan\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/ac89d0281f4fb596bfaa0bc1e746c8a6\"},\"headline\":\"Logrotate: Managing Log Files in Linux\",\"datePublished\":\"2024-07-17T10:00:50+00:00\",\"dateModified\":\"2024-08-04T21:19:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/logrotate-managing-log-files-in-linux\\\/\"},\"wordCount\":1054,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/logrotate-managing-log-files-in-linux\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/Dracula-Servers-Thumbnail-46.png\",\"keywords\":[\"How to manage log files with logrotate\",\"How to use logrotate on linux\",\"Logrotate on Linux\"],\"articleSection\":[\"Getting Started\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/logrotate-managing-log-files-in-linux\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/logrotate-managing-log-files-in-linux\\\/\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/logrotate-managing-log-files-in-linux\\\/\",\"name\":\"Logrotate: Managing Log Files in Linux - Dracula Servers Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/logrotate-managing-log-files-in-linux\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/logrotate-managing-log-files-in-linux\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/Dracula-Servers-Thumbnail-46.png\",\"datePublished\":\"2024-07-17T10:00:50+00:00\",\"dateModified\":\"2024-08-04T21:19:11+00:00\",\"description\":\"Logrotate is a tool for managing log files in Linux, providing flexibility and control over log file rotation, compression, and maintenance\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/logrotate-managing-log-files-in-linux\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/logrotate-managing-log-files-in-linux\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/logrotate-managing-log-files-in-linux\\\/#primaryimage\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/Dracula-Servers-Thumbnail-46.png\",\"contentUrl\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/Dracula-Servers-Thumbnail-46.png\",\"width\":1280,\"height\":720,\"caption\":\"Logrotate on Linux: Managing Log Files in Linux\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/logrotate-managing-log-files-in-linux\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Logrotate: Managing Log Files in Linux\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/\",\"name\":\"Dracula Servers Tutorials\",\"description\":\"Dedicated Servers\",\"publisher\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#organization\",\"name\":\"Dracula Servers\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/dracula_full_logo_smaller.png\",\"contentUrl\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2016\\\/06\\\/dracula_full_logo_smaller.png\",\"width\":1625,\"height\":200,\"caption\":\"Dracula Servers\"},\"image\":{\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/draculaservers.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/ac89d0281f4fb596bfaa0bc1e746c8a6\",\"name\":\"Abdul Mannan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g\",\"caption\":\"Abdul Mannan\"},\"description\":\"An individual trying to decipher the enigmas of technology by the sheer driving force of curiosity. Interested in learning new skills and being better at those skills than the lot.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Logrotate: Managing Log Files in Linux - Dracula Servers Tutorials","description":"Logrotate is a tool for managing log files in Linux, providing flexibility and control over log file rotation, compression, and maintenance","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/","og_locale":"en_US","og_type":"article","og_title":"Logrotate: Managing Log Files in Linux - Dracula Servers Tutorials","og_description":"Logrotate is a tool for managing log files in Linux, providing flexibility and control over log file rotation, compression, and maintenance","og_url":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/","og_site_name":"Dracula Servers Tutorials","article_published_time":"2024-07-17T10:00:50+00:00","article_modified_time":"2024-08-04T21:19:11+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46.png","type":"image\/png"}],"author":"Abdul Mannan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Abdul Mannan","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/#article","isPartOf":{"@id":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/"},"author":{"name":"Abdul Mannan","@id":"https:\/\/draculaservers.com\/tutorials\/#\/schema\/person\/ac89d0281f4fb596bfaa0bc1e746c8a6"},"headline":"Logrotate: Managing Log Files in Linux","datePublished":"2024-07-17T10:00:50+00:00","dateModified":"2024-08-04T21:19:11+00:00","mainEntityOfPage":{"@id":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/"},"wordCount":1054,"commentCount":0,"publisher":{"@id":"https:\/\/draculaservers.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46.png","keywords":["How to manage log files with logrotate","How to use logrotate on linux","Logrotate on Linux"],"articleSection":["Getting Started"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/","url":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/","name":"Logrotate: Managing Log Files in Linux - Dracula Servers Tutorials","isPartOf":{"@id":"https:\/\/draculaservers.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/#primaryimage"},"image":{"@id":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46.png","datePublished":"2024-07-17T10:00:50+00:00","dateModified":"2024-08-04T21:19:11+00:00","description":"Logrotate is a tool for managing log files in Linux, providing flexibility and control over log file rotation, compression, and maintenance","breadcrumb":{"@id":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/#primaryimage","url":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46.png","contentUrl":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2024\/08\/Dracula-Servers-Thumbnail-46.png","width":1280,"height":720,"caption":"Logrotate on Linux: Managing Log Files in Linux"},{"@type":"BreadcrumbList","@id":"https:\/\/draculaservers.com\/tutorials\/logrotate-managing-log-files-in-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/draculaservers.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Logrotate: Managing Log Files in Linux"}]},{"@type":"WebSite","@id":"https:\/\/draculaservers.com\/tutorials\/#website","url":"https:\/\/draculaservers.com\/tutorials\/","name":"Dracula Servers Tutorials","description":"Dedicated Servers","publisher":{"@id":"https:\/\/draculaservers.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/draculaservers.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/draculaservers.com\/tutorials\/#organization","name":"Dracula Servers","url":"https:\/\/draculaservers.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/draculaservers.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2016\/06\/dracula_full_logo_smaller.png","contentUrl":"https:\/\/draculaservers.com\/tutorials\/wp-content\/uploads\/2016\/06\/dracula_full_logo_smaller.png","width":1625,"height":200,"caption":"Dracula Servers"},"image":{"@id":"https:\/\/draculaservers.com\/tutorials\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/draculaservers.com\/tutorials\/#\/schema\/person\/ac89d0281f4fb596bfaa0bc1e746c8a6","name":"Abdul Mannan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2809442d44177cab4f90e1d9b3295560462063881ca1374b6d597d8f0b48fc21?s=96&d=mm&r=g","caption":"Abdul Mannan"},"description":"An individual trying to decipher the enigmas of technology by the sheer driving force of curiosity. Interested in learning new skills and being better at those skills than the lot."}]}},"_links":{"self":[{"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/posts\/3480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/comments?post=3480"}],"version-history":[{"count":1,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/posts\/3480\/revisions"}],"predecessor-version":[{"id":3482,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/posts\/3480\/revisions\/3482"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/media\/3481"}],"wp:attachment":[{"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/media?parent=3480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/categories?post=3480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/draculaservers.com\/tutorials\/wp-json\/wp\/v2\/tags?post=3480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}