From d18a7f2a288b9ce1aa7fb77ed75f98a2f4413c41 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Thu, 21 Aug 2025 21:24:28 +0200 Subject: [PATCH] chore(systemd): extend commands for cleaning up --- knowledge base/systemd.md | 7 +++++++ snippets/systemd.sh | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/knowledge base/systemd.md b/knowledge base/systemd.md index 48caef8..95fca46 100644 --- a/knowledge base/systemd.md +++ b/knowledge base/systemd.md @@ -132,8 +132,13 @@ journalctl --no-full # Print everything. journalctl -a +# Rotate journal files. +# Marks the journal logs currently active as archive, and creates fresh new logs. +sudo journalctl --rotate + # Show current logs disk usage. journalctl --disk-usage +sudo du -sh '/var/log/journal' # Delete old logs. sudo journalctl --vacuum-size='1G' @@ -324,6 +329,7 @@ Restart the `systemd-resolved` service to apply the new settings. - [Suspend and hibernate] - [Changing DNS with systemd-resolved] - [systemctl Commands: Restart, Reload, and Stop Service] +- [How to Clear Systemd Journal Logs] [changing dns with systemd-resolved]: https://notes.enovision.net/linux/changing-dns-with-resolve +[How to Clear Systemd Journal Logs]: https://linuxhandbook.com/clear-systemd-journal-logs/ [how to disable systemd-resolved in ubuntu]: https://askubuntu.com/questions/907246/how-to-disable-systemd-resolved-in-ubuntu [how to set hostname using hostnamectl command?]: https://linuxhint.com/set-hostname-using-hostnamectl-command/ [how to set time, timezone and synchronize system clock using timedatectl command]: https://www.tecmint.com/set-time-timezone-and-synchronize-time-using-timedatectl-command/ diff --git a/snippets/systemd.sh b/snippets/systemd.sh index fcab440..608f19e 100644 --- a/snippets/systemd.sh +++ b/snippets/systemd.sh @@ -16,3 +16,18 @@ sudo hostnamectl set-hostname --pretty 'prometheus' sudo systemctl list-units --state='failed' sudo systemctl hybrid-sleep && exit + +# Check how much space is taken up by logs +sudo journalctl --disk-usage +sudo du -sh '/var/log/journal' + +# Rotate journal files. +# Marks the journal logs currently active as archive, and creates fresh new logs. +sudo journalctl --rotate + +# Delete journal entries older than some time +sudo journalctl --vacuum-time='2d' + +# Restrict logs up to some size. +# Deletes log files until the disk space they take falls below the specified size. +sudo journalctl --vacuum-size='100M'