Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security, Veeam & DevOps

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form

How To Use Logrotate For Managing Log Files In Ubuntu Linux

Posted on 26/06/202314/08/2026 Raphael Gab-Momoh By Raphael Gab-Momoh No Comments on How To Use Logrotate For Managing Log Files In Ubuntu Linux
  1. Home
  2. Linux
  3. 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.

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 Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
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

  • linuxnethero
    Adding a subnetwork interface to an existing network interface Linux
  • How to Set Up and Configure a Squid Proxy Server Linux
  • Linux Shell Scripting 1
    Write a Shell Script that Count Lines and Words in a File Linux
  • image 129
    How to deploy Ansible AWX on centos 8 Linux
  • APACHECASS FEATURE
    How to Install and Configure Apache Cassandra on Linux Server Linux
  • Synergy software kvm
    Why Software KVMs such as Synergy is replacing Hardware KVMs Linux

More Related Articles

linuxnethero Adding a subnetwork interface to an existing network interface Linux
How to Set Up and Configure a Squid Proxy Server Linux
Linux Shell Scripting 1 Write a Shell Script that Count Lines and Words in a File Linux
image 129 How to deploy Ansible AWX on centos 8 Linux
APACHECASS FEATURE How to Install and Configure Apache Cassandra on Linux Server Linux
Synergy software kvm Why Software KVMs such as Synergy is replacing Hardware KVMs Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

vexpert-badge-stars-5

Virtual Background

VEEAMLEGEND

Categories

veeaam100

Veeam Vanguard

  • VM failed to Start on Hyper V e1781126442904
    Fix an error occurred while attempting to start selected VM on Hyper-V Virtualization
  • 87a26c60 0001 0004 0000 000001423515 w948 r1.77 fpx54.99 fpy56.04
    Administer LXC Containers: Easy Guide Virtualization
  • macOS
    How to upgrade macOS Big Sur to macOS Monterey Mac
  • HyperV 1
    An error occurred while attempting to connect to the server: Check if the Virtual Machine Management service is running or you are not authorized to connect to this server Virtualization
  • WonderFox Video Watermark
    Install and use WonderFox Video Watermark Windows
  • Screenshot 2020 05 14 at 19.09.08
    How to backup a Cisco IOS Network | Monitoring
  • Windows Server 2019
    The virtual machine has terminated unexpectedly during startup with exit code 1 (1×0): Failed to open a session for the virtual machine Windows Server 2019 Virtualization
  • schedulepythontasksinWindows
    Task Scheduler shows task still running despite successful 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,759 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Contact
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon
  • Bsky

Tags

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

Copyright © 2026 TechDirectArchive

Loading Comments...

You must be logged in to post a comment.