How to clean up log systemd journal

I. Introduction

On any server, logs generated during use can easily take up a lot of storage space. And in that, the log accounts for quite a lot and is quite common on Linuxjournal servers.

Normally, the log journal will be located in one of the following two paths:

/var/log/journal/
Or
/run/log/journal/

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

du -sh /var/log/journal/
Or
du -sh /run/log/journal/

For example, the results returned as below, your journal size occupies 8.0 M:
how-to-clear-don-dep-log-systemd-journal

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

II. Clean up log systemd journal

To clean up the systemd journal, we need to SSH into our server first. Or at least access the server with a user with  sudo.

After successfully SSHing, we can refer to some of the following ways to clean the systemd journal log.

Method 1: Delete log systemd journal older than X days

In this first way, I will help you delete systemd journal logs older than 10 days. And this is also the way I use most often.

 journalctl –vacuum-time=10d

 

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

This way we can choose to delete systemd journal logs if their size exceeds X GB, X MB..etc…

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

journalctl --vacuum-size=20M

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

journalctl --vacuum-size=1G

After the cleanup is complete, you can check the remaining log space on the system with one of the following two commands:

du -sh /var/log/journal/
Or
du -sh /run/log/journal/
And you can completely configure one of the above log clearing commands into Crontab. From there, your system will automatically clean according to the set schedule.

III. Summary

Hopefully with the above two ways of cleaning the systemd journal log of We will help you free up a lot of memory on the system. In addition to the systemd journal log, we have many other logs, but in this article I only mention the systemd journal log. Since different Linux systems will use different services, the logs will also vary.

On this page