❤️ AZDIGI has officially updated to a new blog system. However, some posts may have incorrect or mismatched images. Please click the Report article button at the bottom of the post so AZDIGI can update as quickly as possible. Thank you!

This article will help you with some ways to clean up the systemd journal log in order to free up the memory usage of this type of log.

I. Introduction

On any server, logs generated during usage can easily consume a lot of storage memory. Among them, the journal log takes up a relatively large and common space on Linux servers.

Usually, the journal log will be located at one of the following two paths:

AZDIGI Tutorial
/var/log/journal/
Hoặc
/run/log/journal/
    

And we can easily check their size with one of the following commands:

AZDIGI Tutorial
du -sh /var/log/journal/
Hoặc
du -sh /run/log/journal/
    

For example, if the returned result is as below, your journal log takes up 4.1GB:

AZDIGI Tutorial
du -hs /var/log/journal/
4.1G	/var/log/journal/
    

Usually, we don’t really need that many logs, so let’s clean them up with some of the methods below.

II. Cleaning up the systemd journal log

To clean up the systemd journal log, we need to SSH into our server first. Or at least log in to the server with a user with sudo privileges. If you don’t know how to SSH into your VPS/Server, you can refer to the following tutorial:

After successfully SSH, we can refer to some ways to clean up the systemd journal log as follows:

Method 1: Delete systemd journal logs older than X days

In this first method, I will help you delete systemd journal logs older than 10 days. And this is also the most commonly used method.

AZDIGI Tutorial
journalctl --vacuum-time=10d
    

Here is my result after running the command: Depending on each system, the amount of storage cleared will vary.

how-to-clear-log-systemd-journal
3.0G of storage space was freed up after cleaning up the systemd journal log.

Method 2: Clean up the systemd journal log if it exceeds X

With this method, we can choose to delete the systemd journal log if its size exceeds XGB, XMB, and so on.

If you want to keep only 20MB of logs, you can use the following command:

AZDIGI Tutorial
journalctl --vacuum-size=20M
    

Or if you want to keep 1GB, you can use the following command:

AZDIGI Tutorial
journalctl --vacuum-size=1G
    

After cleaning up, you can check the remaining journal log size on the system with either of the following commands:

AZDIGI Tutorial
du -sh /var/log/journal/
Hoặc
du -sh /run/log/journal/
    
Check the size of the journal log.

And you can also configure one of the log deletion commands in Crontab. From then on, your system will automatically clean up according to the schedule set.

III. Summary

Hopefully, these two methods of cleaning up the systemd journal log from AZDIGI will help you free up a lot of storage space on your system. Besides the systemd journal log, there are many other logs, but in this article, I only mentioned the systemd journal log. Because different Linux systems will use different services, the logs will also vary.

Share:
This article has been reviewed by AZDIGI Team

About the author

Thạch Phạm

Thạch Phạm

Đồng sáng lập và Giám đốc điều hành của AZDIGI. Có hơn 15 năm kinh nghiệm trong phổ biến kiến thức liên quan đến WordPress tại thachpham.com, phát triển website và phát triển hệ thống.

10+ years serving 80,000+ customers

Start your web project with AZDIGI