Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » Linux » How To Use Logrotate For Managing Log Files In Ubuntu Linux
  • Remote Desktop Connection Windows 10 min
    Fix Remote Desktop Connection issues (Error 0x204) Windows
  • Mendeley Error Code ACLx80sr
    Fix Mendeley Cite Error has occurred: ECITE40001 (ac1x80sr) JIRA|Confluence|Apps
  • DevOps
    Create an App Service Plan with Continuous Deployment to deploy a .NET Application from GitHub AWS/Azure/OpenShift
  • DUE Deligence vs Due Care
    Relating Due Diligence and Due Care to Veeam Backup and Replication Backup
  • Featured image Two Factor Authentication
    Change Two-Factor Authentication in Microsoft 365/Office 365 Network | Monitoring
  • Screenshot 2022 03 20 at 21.08.50
    How to integrate AWS CodeBuild and AWS CodeCommit to SonarCloud AWS/Azure/OpenShift
  • Install Packages to Amazon Virtual Machine Using Terraform
    How to Install Packages to Amazon VM using Terraform AWS/Azure/OpenShift
  • RDP
    Fix Windows 11 Remote Desktop Connectivity Error code 0x204 Windows

How To Use Logrotate For Managing Log Files In Ubuntu Linux

Posted on 26/06/202320/12/2023 Raphael Gab-Momoh By Raphael Gab-Momoh No Comments on How To Use Logrotate For Managing Log Files In Ubuntu Linux
Manage Log-Files-via-Logrotate

This article will show you how To Use Logrotate For Managing Log Files In Ubuntu Linux. To conserve disk space and keep the system operating efficiently, Logrotate is a software program found in Unix/Linux systems that controls the automated rotation, compression, and deletion of log files. It enables administrators to arrange routine log file rotations to prevent accumulating multiple, possibly troublesome log files. Please see Fast user switching: How to create a desktop shortcut in Windows 10 to switch User Accounts, How to change your Windows Computer login Password, How to detect who disabled a user in Active Directory – Best Monitoring Tools and Software, and How to setup WatchGuard Log Server.

For information on which log files need rotation, the frequency of process, and the number of rotated logs to keep, the utility program consults its configuration file (/etc/logrotate.conf or a custom file given on the command line) when it is run.

Then it carries out the necessary operations, like compressing and archiving older log files and creating new ones with a new one. Please also see How to find out who restarted Windows Server, How to Deploy a React Application on Netlify, and Why you should not use Public DNS in Production: Change DNS Server in Windows.

Step 1-Check The Logrotate Version: Use Logrotate For Managing Log Files In Linux

Ubuntu comes with the software program pre-installed. The instructions below will update your package list and get the package if you need to install it, though:

sudo apt update
sudo apt install logrotate
install-logratate-after-upgrading-system
install logrotate

To confirm the installation of the system utility, ask for Logrotate’s version information. If you are using a non-Ubuntu server, you can confirm installation using the command below:

logrotate --version
logrotate-version
checking the version of the log rotate

Some of the configuration options covered in this tutorial may not work properly if you install the system utility and the version number is significantly different. Read the manual (man) page of the version of utility program you are using to find the documentation

Step 2- Take a closer look at the Logrotate configuration: Use Logrotate For Managing Log Files In Linux

Typically, you can find information about Logrotate’s setup in two locations on Ubuntu:

  1. /etc/logrotate.conf: The file /etc/logrotate.conf, which also contains specific default settings set up the rotation of a few logs not owned by any system packages. You can retrieve the configuration from any file in the /etc/logrotate.d directory using the include statement.
  2. /etc/logrotate.d/ : Any programs you install requiring log rotation assistance will place their utility settings in /etc/logrotate.d/. Additionally, for essential system tools like apt, dpkg, rsyslog, and others, there should already be files on a typical installation.

Let’s see what’s inside the /etc/logrotate.d.cat configuration file for a particular file for the apt package utility using the command:

cat /etc/logrotate.d/apt
examining-the-file
content of Logrotate configuration file

This file provides configuration blocks for the term.log and history.log log files located in the /var/log/apt directory. Meanwhile, both of them have the same choices. For settings not provided in these configuration sections, the system will use the default values or those specified in /etc/logrotate.conf.

Furthermore, any setting in a system utility file overrides the default values for logrotate, set in /etc/logrotate.conf. As shown from the screenshot above, the following parameters are configured for apt logs:

Rotate 12: preserve twelve previous log files. The rotate 4 default is replaced with this.
Compress: Compress rotated files. By default, this utilizes gzip, which produces files with a.gz extension. In addition, the compressed option allows you to modify the compression command
missingOk: Don’t write an error message if the log file is missing.
notifempty: If the log file is empty, do not rotate it.

Step 3- Creating an Example Configuration: Use Logrotate to manage Log File

For a hypothetical web server that stores an access.log and an error.log into /var/log/my-app/. It operates under the www-data group and user.

Open a new file in the /etc/logrotate.d directory using vim or your preferred editor to add a setting for the my-app log files using the command below:

sudo vim /etc/logrotate.d/my-app

Include the lines below in your new configuration file:

/var/log/my-app/*.log {
	daily
	missingok
	rotate 14
	compress
	notifempty
	create 0640 www-data www-data
	sharedscripts
	postrotate
		systemctl reload my-app
	endscript
}

these are a few of the new configuration instructions in this file:

To save and quit vim, Hit the escape button on your keyboard and type :wq.

type-colon-wq-to-quit-vim
Hit the escape button, colon wq to quit Vim

You can test the config file by doing a dry run:

sudo logrotate /etc/logrotate.conf --debug

This command activates debug mode, invokes logrotate, and specifies the standard configuration file.

testing-logrotate
testing logrotate

Summary

The article explains how Logrotate helps manage log files in Linux by automating compression, archiving, and deletion based on predefined criteria.

It offers a step-by-step guide on installation, configuration, and customization options. Logrotate proves valuable for Linux system administrators handling log file management.

I hope you found this blog post helpful for using Logrotate to manage Log Files In Ubuntu Linux. Please let me know in the comment section if you have any questions.

Rate this post

Thank you for reading this post. Kindly share it with others.

  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on Bluesky (Opens in new window) Bluesky
  • Click to share on Threads (Opens in new window) Threads
  • Click to share on Nextdoor (Opens in new window) Nextdoor
Linux Tags:Ubunt 20.04 LTS, Ubuntu

Post navigation

Previous Post: Create App Service Resource with Azure CLI
Next Post: How to Setup GitLab Runner on WSL

Related Posts

  • openstack ola
    Openstack Deployment with Devstack Linux
  • Convert PEM to PPK 1
    Convert a PEM Key to a PPK Key on a Linux and Windows AWS/Azure/OpenShift
  • centos feature
    How to change the system time zone under RedHat and CentOS Linux
  • redisf
    How to install Redis on Linux System Linux
  • Synergy software kvm
    Why Software KVMs such as Synergy is replacing Hardware KVMs Linux
  • Linux Shell Scripting 1
    Write a Shell Script that Count Lines and Words in a File Linux

More Related Articles

openstack ola Openstack Deployment with Devstack Linux
Convert PEM to PPK 1 Convert a PEM Key to a PPK Key on a Linux and Windows AWS/Azure/OpenShift
centos feature How to change the system time zone under RedHat and CentOS Linux
redisf How to install Redis on Linux System Linux
Synergy software kvm Why Software KVMs such as Synergy is replacing Hardware KVMs Linux
Linux Shell Scripting 1 Write a Shell Script that Count Lines and Words in a File Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

sysadmin top30a

  • Remote Desktop Connection Windows 10 min
    Fix Remote Desktop Connection issues (Error 0x204) Windows
  • Mendeley Error Code ACLx80sr
    Fix Mendeley Cite Error has occurred: ECITE40001 (ac1x80sr) JIRA|Confluence|Apps
  • DevOps
    Create an App Service Plan with Continuous Deployment to deploy a .NET Application from GitHub AWS/Azure/OpenShift
  • DUE Deligence vs Due Care
    Relating Due Diligence and Due Care to Veeam Backup and Replication Backup
  • Featured image Two Factor Authentication
    Change Two-Factor Authentication in Microsoft 365/Office 365 Network | Monitoring
  • Screenshot 2022 03 20 at 21.08.50
    How to integrate AWS CodeBuild and AWS CodeCommit to SonarCloud AWS/Azure/OpenShift
  • Install Packages to Amazon Virtual Machine Using Terraform
    How to Install Packages to Amazon VM using Terraform AWS/Azure/OpenShift
  • RDP
    Fix Windows 11 Remote Desktop Connectivity Error code 0x204 Windows

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,839 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.