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
  • App Locker
    Harden your Veeam Backup Server with Microsoft AppLocker Windows
  • windows 10 keyboard shortcut 1024x512 1
    How to create a Desktop shortcut in Windows Windows
  • AWS Scheduled Events
    View Scheduled Events on AW using AWS Web Console and CLI AWS/Azure/OpenShift
  • ccsC
    NTuser.dat file: How to correctly load Windows Registry Hive Windows
  • msinfo32 thumbnail
    How to use MSINFO32 to view System Information Windows
  • images 8
    Microsoft Direct Access: Now Always On VPN Windows Server
  • Wingettool
    Install and Manage Applications with Winget Windows
  • Banner
    How to Deploy GitHub Repositories to cPanel using GitHub Actions Automation

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.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Pocket (Opens in new window) Pocket
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
  • Share on Threads (Opens in new window) Threads
  • 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

  • Feature image nagios
    How to Install and Configure Nagios on Ubuntu Linux
  • Header image
    How to setup a Third-Party DNS Server on a Linux Server Linux
  • featuredpkg
    How to solve /var/lib/dpkg/lock Error in Ubuntu Linux Linux
  • PlayF
    How to Install PlayonLinux on a Linux System Linux
  • featureunions
    How to Install Unison on Linux System Linux
  • Ubuntu on Windows
    Install Ubuntu 20.04 LTS on Windows via WSL Linux

More Related Articles

Feature image nagios How to Install and Configure Nagios on Ubuntu Linux
Header image How to setup a Third-Party DNS Server on a Linux Server Linux
featuredpkg How to solve /var/lib/dpkg/lock Error in Ubuntu Linux Linux
PlayF How to Install PlayonLinux on a Linux System Linux
featureunions How to Install Unison on Linux System Linux
Ubuntu on Windows Install Ubuntu 20.04 LTS on Windows via WSL 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

  • App Locker
    Harden your Veeam Backup Server with Microsoft AppLocker Windows
  • windows 10 keyboard shortcut 1024x512 1
    How to create a Desktop shortcut in Windows Windows
  • AWS Scheduled Events
    View Scheduled Events on AW using AWS Web Console and CLI AWS/Azure/OpenShift
  • ccsC
    NTuser.dat file: How to correctly load Windows Registry Hive Windows
  • msinfo32 thumbnail
    How to use MSINFO32 to view System Information Windows
  • images 8
    Microsoft Direct Access: Now Always On VPN Windows Server
  • Wingettool
    Install and Manage Applications with Winget Windows
  • Banner
    How to Deploy GitHub Repositories to cPanel using GitHub Actions Automation

Subscribe to Blog via Email

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

Join 1,834 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

Active Directory AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.