How to clear journalctl

  • I couldn't find in google any safe way to clear systemd journal. Do anyone know any safe and reliable way to do so?

    Let's say I was experimenting with something and my logs got cluttered with various error messages. Moreover I'm displaying my journal on my desktop by using Conky. I really don't want to see those errors as they remind me an awful day I was fixing this stuff, I want to feel like a fresh man after this horror. I think everyone will agree that this is a valid reason to clear the logs :P .

  • Michael

    Michael Correct answer

    6 years ago

    The self maintenance method is to vacuum the logs by size or time.

    Retain only the past two days:

    journalctl --vacuum-time=2d
    

    Retain only the past 500 MB:

    journalctl --vacuum-size=500M
    

    man journalctl for more information.

    Nice command, but didn't work for me on openSUSE 13.2 (the current stable release). It's known that Arch is usually at the cutting edge when it comes to kernel and userland programs, so I speculated that vacuum options might have been recently added to systemd and simply haven't precipitated down into my distro. Confirmed the fact here in Lennart's announcement on Dec 10 2014 http://techupdates.com/go/1002774 that this command was added in systemd v218. Just adding this comment incase any one else like me who is not on Arch has a similar issue. Upvoted anyway.

    I just used 'journalctl --vacuum-time=1d' to fix a situation where new log messages weren't showing with 'journalctl -f'. Apparently my system time had temporarily jumped about a day forward for a while, then recovered, and journalctl was using the log event timestamps from that future time as the journal tail.

    Didn't work in version "systemd 229" on Ubuntu 16.04. `journalctl --vacuum-size=1K` then `journalctl` still shows way more than 1K. It shows all the messages since the last boot.

    -1 Did not work on Fedora 25, systemd 231. Command used: `sudo journalctl --vacuum-time=1s && sudo journalctl --vacuum-size=1K && sudo systemctl restart systemd-journald && journalctl -u systemd-resolved`

    It seems that this only clears archived logs, not active ones. I tried running `journalctl --flush --rotate` before `journalctl --vacuum-time=1s` and it removed more stuff, although still not everything.

    The documentation doesn't seem so clear to me. Does it always stay set to 2d (in your example)? Or is 2d from the time you run the command? Maybe I'm not understanding how this works exactly.

    journalctl: unrecognized option '--rotate'

    Careful though, I used `sudo journalctl --vacuum-time=7d` and was only left with logs from today... Seems like a buggy feature

    gotta use sudo, so put a `#` in front puhlease

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM