Your Search Bar For Shrewd Tips

How Do I Clear Journalctl Logs?


If your Linux system is running low on disk space, or you need to remove old system logs, you may be wondering: How do I clear journalctl logs? The safest way is to use the built-in journalctl vacuum options. These remove archived systemd journal files according to their age, size, or number, without manually deleting files that journald may still be using.

This guide explains how to check journal usage, reduce the size of journalctl logs, set automatic limits, and troubleshoot common issues. It also covers what “clearing” logs actually means, so you can choose an appropriate retention period instead of removing useful diagnostic information by accident.

What Are journalctl Logs?

journalctl is the command-line tool used to read logs collected by systemd-journald. The journal can include messages from the Linux kernel, system services, and other applications. These records can help diagnose boot failures, service errors, hardware problems, and security events.

Journal files may be stored in one of two locations. Persistent journals are usually kept under /var/log/journal/, so they remain available after a reboot. Volatile journals are usually stored under /run/log/journal/ and are typically cleared when the system restarts. The location and retention behavior depend on your system’s configuration.

Unlike a simple text log, the systemd journal uses structured files that journald manages. For that reason, use journalctl to remove journal data rather than deleting files manually while the service is running.

Check How Much Space the Journal Uses

Before clearing logs, check how much disk space the journal is consuming. Run:

sudo journalctl --disk-usage

The command reports the approximate disk space used by active and archived journal files. For example, it may show that archived and active journals use several hundred megabytes. This gives you a baseline and helps you decide whether cleanup is necessary.

You can also inspect the journal files on disk. Persistent files are commonly located in /var/log/journal/, while volatile files are commonly in /run/log/journal/. Use sudo if you need to list these protected directories:

sudo du -sh /var/log/journal /run/log/journal 2>/dev/null

A directory may not exist if your system uses the other storage mode or has not created a journal there. The journal’s reported usage and the directory size may differ slightly because of file allocation and other system details.

Clear journalctl Logs by Age

To remove archived journal files older than a chosen period, use --vacuum-time. For example, this command removes archived journal data that is more than seven days old:

sudo journalctl --vacuum-time=7d

You can choose another supported time value, such as 2weeks, 1month, or 1year. A shorter period frees space more aggressively, but it also leaves you with less history when investigating an older issue.

Vacuuming applies to archived journal files. Journald may still have an active file open, so an age-based cleanup does not necessarily make the journal empty. This is expected behavior: the service keeps current data available for ongoing logging.

Clear journalctl Logs by Size

If you need to bring journal usage below a particular amount, use --vacuum-size. For example, to limit archived journal data to roughly 500 megabytes:

sudo journalctl --vacuum-size=500M

Other examples include 100M for a tighter limit or 2G for a larger allowance. The vacuum operation removes archived files as needed to reach the requested size. Because active journal files are not removed by vacuuming, the total disk usage can remain above the specified value.

Size-based cleanup is useful on servers with limited storage, virtual machines, and small Linux devices. It provides a practical way to manage disk use without selecting an exact retention period. Keep in mind that a smaller limit means older troubleshooting information may disappear sooner.

Limit the Number of Archived Journal Files

You can also remove archived journal files until only a chosen number remain by using --vacuum-files. For example:

sudo journalctl --vacuum-files=5

This asks journald to retain no more than five archived journal files. It does not mean the system will contain only five total files, because active files may remain in use. This option can be helpful when you want a simple file-count limit rather than a time or disk-size target.

Rotate the Journal Before Vacuuming

Vacuum commands only remove archived journal files; they do not delete the active journal file. If you want journald to close its current file and start a new one before cleanup, rotate the journal first:

sudo journalctl --rotate
sudo journalctl --vacuum-size=100M

You can use --vacuum-time or --vacuum-files after rotation instead of --vacuum-size. Rotation makes the current file eligible to become an archived file, but it does not guarantee that every journal file will be deleted. The active journal and newly created files may remain.

For example, to rotate and then remove archived files older than one day, run:

sudo journalctl --rotate
sudo journalctl --vacuum-time=1d

After the commands finish, check usage again with sudo journalctl --disk-usage. Remember that journald may continue writing new entries immediately, so usage can begin increasing again.

Can You Delete All journalctl Logs?

There is an important distinction between removing old archived logs and deleting every journal entry. The journalctl vacuum options are designed to clean up archived files while leaving journald able to operate normally. They are not a promise to erase every active or newly created log file.

For most maintenance tasks, you should not try to force the journal to zero bytes. Instead, rotate the journal and choose a small, reasonable size or retention period. This frees space while preserving the current logging system and at least some recent diagnostic information.

Avoid manually removing files from /var/log/journal/ or /run/log/journal/ while journald is running. Direct deletion can cause confusing results, and it may remove records that are still in use. If you have a specific compliance or privacy requirement to erase logs, follow your organization’s approved procedure and verify the behavior for your Linux distribution. Be aware that logs may also be forwarded to a remote logging server or stored elsewhere.

Set Automatic Journal Size and Retention Limits

To prevent journalctl logs from growing beyond your preferred limits, configure journald rather than repeatedly cleaning the journal by hand. The main configuration file is commonly /etc/systemd/journald.conf. Open it with an editor, such as:

sudo nano /etc/systemd/journald.conf

Look for settings under the [Journal] section. Depending on your needs, you can set options such as:

[Journal]
SystemMaxUse=500M
SystemKeepFree=1G
MaxRetentionSec=2week

SystemMaxUse sets a maximum amount of disk space for persistent journal files, while SystemKeepFree tells journald to leave a specified amount of free space on the file system. MaxRetentionSec sets a maximum age for journal data. The exact behavior can depend on your system and other configuration settings, so consult the local manual page before relying on a particular value:

man journald.conf

For volatile journals, corresponding settings include options such as RuntimeMaxUse and RuntimeKeepFree. After changing the configuration, restart journald so the new settings take effect:

sudo systemctl restart systemd-journald

Restarting the logging service is generally safe, but avoid doing it during critical troubleshooting if you need uninterrupted log collection. You can confirm that the service is running afterward with:

systemctl status systemd-journald

Common journalctl Cleanup Problems

  • Permission denied: Journal files are normally protected. Run cleanup commands with sudo if your account is authorized to administer the system.
  • Disk usage is still high: Vacuuming targets archived files, not necessarily active files. Other logs, caches, application data, or deleted files still held open by a process may also be using space.
  • Logs return after cleanup: This is normal. Services continue writing new messages, so journal usage gradually grows again.
  • There is no persistent journal directory: Your system may be storing logs only in volatile storage, or it may not have created a persistent journal yet. Check your journald configuration and distribution documentation.
  • Old logs are missing after reboot: The system may be configured for volatile storage. Check the Storage setting in /etc/systemd/journald.conf and confirm that persistent journal storage is appropriate for your needs.

If the system is almost out of disk space, check the whole file system as well as the journal. Use df -h to see which mounted file system is full, and investigate large directories before removing data. Journal cleanup will not solve a disk-space problem caused by unrelated files.

Useful journalctl Commands for Verifying Logs

After cleanup, you can still use journalctl to review the entries that remain. For example, show recent messages with:

sudo journalctl -n 50

To view messages from the current boot, run:

sudo journalctl -b

To follow new entries as they are written, use:

sudo journalctl -f

These commands help confirm that journald is working after maintenance. If you are diagnosing a problem, consider saving the relevant output before you vacuum old data.

Conclusion: The Safest Way to Clear journalctl Logs

To clear journalctl logs safely, first check usage with sudo journalctl --disk-usage, then use a vacuum option that matches your goal. Choose --vacuum-time to remove older archived logs, --vacuum-size to reduce disk use, or --vacuum-files to limit the number of archived files. Rotate the journal first when you want the current file closed before cleanup.

For ongoing control, set suitable journald limits in /etc/systemd/journald.conf and verify the result after restarting the service. Avoid manually deleting journal files, and retain enough recent history to troubleshoot future problems. This approach clears unnecessary log data while keeping system logging reliable.


Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

Shrewdnia

Shrewdnia

Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


💡 Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments 👇

Back to blog

Leave a comment

JOIN THE SHREWDNIA COMMUNITY FORUM

What do you think?

Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

Join the Forum →