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 .
- 12This is the top search result when looking for a way to clear journal entries. However, none of the answers below actually answer the question, because they either delete old logs or all logs. None of them are about clearing recent or specific logs. I posted a guide for deleting specific log entries atunix.stackexchange.com/questions/272662/…Rob W– Rob W2020-10-27 23:00:17 +00:00CommentedOct 27, 2020 at 23:00
- 8I got the best result with
journalctl --flush --rotate --vacuum-time=1sandjournalctl --user --flush --rotate --vacuum-time=1s.accdias– accdias2023-04-22 14:36:13 +00:00CommentedApr 22, 2023 at 14:36 - 1@Rob, no. The question asks to clear logs, not delete specific ones. Though you input might be valuable for some too.Alex Martian– Alex Martian2024-01-14 10:35:15 +00:00CommentedJan 14, 2024 at 10:35
- To see the correct answer, see Jan Warchoł's answer (currently ranked #3, and NOT marked as accepted answer). @accdias's answer in the comment above is good too.Robin Davies– Robin Davies2024-07-24 04:37:53 +00:00CommentedJul 24, 2024 at 4:37
16 Answers16
The self maintenance method is to vacuum the logs by size or time.
Retain only the past two days:
journalctl --vacuum-time=2dRetain only the past 500 MB:
journalctl --vacuum-size=500Mman journalctl for more information.
- 17Nice 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 2014techupdates.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.Joshua Huber– Joshua Huber2015-04-23 00:33:54 +00:00CommentedApr 23, 2015 at 0:33
- 12Didn't work in version "systemd 229" on Ubuntu 16.04.
journalctl --vacuum-size=1Kthenjournalctlstill shows way more than 1K. It shows all the messages since the last boot.Dan Dascalescu– Dan Dascalescu2016-09-10 04:23:00 +00:00CommentedSep 10, 2016 at 4:23 - 65It seems that this only clears archived logs, not active ones. I tried running
journalctl --flush --rotatebeforejournalctl --vacuum-time=1sand it removed more stuff, although still not everything.user60039– user600392017-02-07 19:42:48 +00:00CommentedFeb 7, 2017 at 19:42 - 4The 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.jersey bean– jersey bean2017-08-03 01:49:27 +00:00CommentedAug 3, 2017 at 1:49
- 7@AlexanderMills Hi Alexander. If someone knows that "#" means "as root", they certainly know that system management tasks always require special privileges. Also, depending on your setup you don't necessarily have to use
sudo, e. g. you can work as root. Also it really hinders you from copy pasting commands directly to terminal, especially if they're multi-line. This also applies to lines beginning with "$", of course. It was never neither useful, nor esthetic. And since there are code blocks, you don't even have a problem to recognise things as commands.bot47– bot472021-01-27 08:33:09 +00:00CommentedJan 27, 2021 at 8:33
You don't typically clear the journal yourself. That is managed by systemd itself and old logs are rotated out as new data comes in. The correct thing to do would be to schedule journald to only keep as much data as you are interested in. The most usual thing to adjust is the total disk space it is allowed to take up. Once it crosses this boundry it will start pitching old entries to stay near this value.
You can set this in/etc/systemd/journald.conf like so:
SystemMaxUse=100MThis will be enforced on the next reboot or restart of the journald service:
$ systemctl restart systemd-journald- 30Ok, but there are also untypical situations. I know that most of them is just aesthetics as a reason, but aesthetics is a valid reason for human being ;) .Łukasz Zaroda– Łukasz Zaroda2014-06-27 12:08:12 +00:00CommentedJun 27, 2014 at 12:08
- 4@ŁukaszZaroda In that case you are going to have to define "safe". Normally "I want to blow away something that a daemon is configured to keep" is incompatible with "safe". If you want to force it just shut down the service and zero out the log files. If you want it to work normally you should define the parameters in your question better. What do you mean by "safe"?Caleb– Caleb2014-06-27 12:17:35 +00:00CommentedJun 27, 2014 at 12:17
- 2By safe, I mean that after clearing it will work as usual, just starting from the new place.Łukasz Zaroda– Łukasz Zaroda2014-06-27 12:19:57 +00:00CommentedJun 27, 2014 at 12:19
- 6It may be not typical situation but sometimes it is necessary to delete old logs due to some systemd's bugs, e.g.bbs.archlinux.org/viewtopic.php?pid=1173031#p1173031anlar– anlar2014-06-27 15:57:28 +00:00CommentedJun 27, 2014 at 15:57
- 18To clean logs after a period of time rather than when they reach a certain size, you can set the parameter
MaxRetentionSecinstead ofSystemMaxUse. Seeman journald.conffor more details.joelostblom– joelostblom2018-03-29 13:08:01 +00:00CommentedMar 29, 2018 at 13:08
Michael's answer is missing one thing: vacuuming only removes archived journal files, not active ones. To get rid of everything, you need to rotate the files first so that recent entries are moved to inactive files.
So, the complete answer to removeall entries seems to be
sudo journalctl --rotatesudo journalctl --vacuum-time=1s(Note that you cannot combine this into onejournalctl command.)
By the way, some distributions have journald configured so that it writes logs to disk (/var/log/journal) while others keep logs in memory (/run/log/journal). I expect that in some cases it may be necessary to usesudo journalctl --flush first to get everything removed.
If you don't have--rotate in your version, you can use the--since argument to filter entries:
--since "2019-01-30 14:00:00"--since today- 9journalctl: unrecognized option '--rotate'stiv– stiv2018-10-07 12:22:35 +00:00CommentedOct 7, 2018 at 12:22
- 14while I get what the other answers are approaching (long term strategy) - the question is simple: how do you clear logs now (maybe you're not interested in the long term for your current task). This answers that question without making other assumptions and adds other great value to understanding journalctl. This should be the answer.Marc– Marc2018-10-20 15:39:36 +00:00CommentedOct 20, 2018 at 15:39
- 5Original question was "how do I reset my logs for debugging purposes". This is the only answer that addresses that. And I'm really glad I found it. The rest are interesting journalctl factoids, but not answers to the questions.Travis Griggs– Travis Griggs2019-10-25 19:08:18 +00:00CommentedOct 25, 2019 at 19:08
- 1Note that this is a one-off command. It sounded to me like it would permanently set the vacuum time to 1 second, but no, this just removes current logs without changing your configuration (which is what I wanted).Luc– Luc2021-05-26 12:13:49 +00:00CommentedMay 26, 2021 at 12:13
- 1This appears to clear all systemd logs. How would you clear all logs pertaining to a particular service while allowing all other sevices to retain their log-entries?Lonnie Best– Lonnie Best2022-06-20 06:34:30 +00:00CommentedJun 20, 2022 at 6:34
On Arch linux, the closest I got was:
- Edit /etc/systemd/journald.conf to set SystemMaxUse=1M
- Restarting journal:
sudo systemctl restart systemd-journald - Resetting SystemMaxUse=200M
- Re-Restarting the journal
On my system, each journal file is 8MB, and the above cleared all but 3, bringing the total size to ~25MB.
My use-case was disabling CoW for BTRFS (just for the journal directory and subdirectories):sudo chattr +C /var/log/journal/*. The problem is, the attribute is only set on newly-created files, thus the desire to flush the journal.
- 6Your use-case was actually not needed. The point of disabling CoW on the journal is that it is frequently written to. That is not the case for the old rotated journal files, they just sit there.Hjulle– Hjulle2015-03-31 10:03:45 +00:00CommentedMar 31, 2015 at 10:03
- 1I've set
SystemMaxUse=1K, restartedsystemd-journald, but journalctl still shows entries I want gone. How is this progress from flat text files?Dan Dascalescu– Dan Dascalescu2016-09-10 04:18:52 +00:00CommentedSep 10, 2016 at 4:18
Since--vacuum-time and--vacuum-size didn't do a thing for me I did the following:
$ sudo find /var/log/journal -name "*.journal" | xargs sudo rm $ sudo systemctl restart systemd-journaldIt's not right, but it worked.
- On Debian Jessie, the path is
/run/log.Synchro– Synchro2018-02-12 18:23:11 +00:00CommentedFeb 12, 2018 at 18:23 - 4This is the currently correct answer. It would be nice if the journalctl command could do this but it appears unable.Kevin Lyda– Kevin Lyda2019-09-26 10:43:33 +00:00CommentedSep 26, 2019 at 10:43
- Some programs do not handle their logs properly and this may break them0x777C– 0x777C2019-12-26 13:42:17 +00:00CommentedDec 26, 2019 at 13:42
- 1This seems to be theonly working command from all the answers here, at least for Ubuntu 18.04. 3 GB of /var/log/journal/* from about 3 years were removed by none of the "vacuum" variants mentioned in other answerdDweia– Dweia2021-03-15 16:00:41 +00:00CommentedMar 15, 2021 at 16:00
- On Arch, the vacuum options cleared some intermediary stuff, but the log was always full of stuff from months ago sans the recent stuff. This is the only answer that truly cleared journalctl outEkriirkE– EkriirkE2023-03-30 14:44:10 +00:00CommentedMar 30, 2023 at 14:44
A very brute force method to clean the entire log:
$ sudo journalctl --vacuum-time=1secondsYou can also use--vacuum-size as Michael mentoined.
- 5Didn't work. Entries for 15 minutes ago still show up, even after running
systemctl restart systemd-journald.Dan Dascalescu– Dan Dascalescu2016-09-10 04:15:38 +00:00CommentedSep 10, 2016 at 4:15 - 1Same here. This didn't work for me either. I'm running CentOS7.jersey bean– jersey bean2017-08-03 01:55:22 +00:00CommentedAug 3, 2017 at 1:55
- 2From the man page "the vacuuming operation only operates on archived journal files."Larsen– Larsen2021-07-16 10:51:25 +00:00CommentedJul 16, 2021 at 10:51
Both --rotate and --vacuum-time=1s didn't work for me on CentOS. I was able to clear it like this:
sudo rm -rf /run/log/journal/*- 1I found 2 directories with hexadecimal name in
./journal. Thejournalctlcommands only works in the most recent one. So I had to delete the old directory manually and that is safe. After I just limit the size in journal conf.KeitelDOG– KeitelDOG2019-02-19 20:40:29 +00:00CommentedFeb 19, 2019 at 20:40 - 2On Ubuntu Server 20.04, that folder you mentioned exists, but there was nothing in it (
ls -lah /run/log/journal/).Lonnie Best– Lonnie Best2020-08-02 12:25:01 +00:00CommentedAug 2, 2020 at 12:25 - 1On Ubuntu the directory appears to be
/var/log/journal/*.Eerik Sven Puudist– Eerik Sven Puudist2020-11-15 20:32:29 +00:00CommentedNov 15, 2020 at 20:32 - Are you sure? What did you do after performing this action and how did you verify? I'm preparing RHEL 7 and RHEL 8 virtual machines for templateing with cloud-init and while loglines with older timestamps appear to be gone I can see the old hostname on the RHEL 7 machine which has no --rotate option. Yes you are messing with journald and delete its files (I'm even restarting journald system unit), but I think systemd in its design to be modern and trustworthy bites back and posts the content it has in memory right back. It might take a reboot, but it's there.LiveWireBT– LiveWireBT2021-01-30 17:32:02 +00:00CommentedJan 30, 2021 at 17:32
- Regarding my previous comment I found that the hostname is compiled in the initrd:unix.stackexchange.com/a/284551/49853 and
dracut -f -vsolves my problem on RHEL 7. I opted for a solution using find since in some shells or under some circumstances expansion may not work:find "/run/log/journal/" "/var/log/journal/" "/var/run/log/journal/" -type f -delete.LiveWireBT– LiveWireBT2021-01-31 03:13:25 +00:00CommentedJan 31, 2021 at 3:13
My previous answer just got deleted for being "duplicated". Well, sorry for not being clear enough in my previous answer, but it was different from existing answers. So here's a more elaborated version:
journalctl -m --vacuum-time=1s did the trick for me.Please DO notice the-m flag, it merges all your journals and then clean them up. Without the-m flag, it didn't clean up anything in my case (on CentOS-7).
Hope it helps.
- Still leaves 8M of logs, according to
journalctl --disk-usageBram– Bram2022-05-28 06:51:29 +00:00CommentedMay 28, 2022 at 6:51 - This should be the accepted solution.
-mflag is important!Alexandr Zarubkin– Alexandr Zarubkin2023-04-06 09:54:41 +00:00CommentedApr 6, 2023 at 9:54
Create this file (and possibly its parent directory):/etc/systemd/journald.conf.d/max-size.conf
With contents:
[Journal]SystemMaxUse=100MThe space will be freed after you reboot or runsudo systemctl restart systemd-journald
This will keep your journald log small now and forever. Because the config is stored in a dedicated file, there is no editing mess and it's easy to remove the config later (or see what exactly have you changed in the past). You can also specify maximum journal entries time with:MaxRetentionSec=3day
- 1Docs for this technique:wiki.archlinux.org/title/Systemd/Journal#Journal_size_limit —wiki.archlinux.org/title/Systemd#Drop-in_filesWoodrowShigeru– WoodrowShigeru2023-07-30 08:21:48 +00:00CommentedJul 30, 2023 at 8:21
I was facing the same situation as you. After some searching, I realize
- It is impossible to clear logs for a specific service without 3rd party script.
journalctl --vacuum-time 1scan only clear archived logs. So you may find that the annoying logs still exist after this command.- You can work around this by first
journalctl --rotate. This command archives logs immediately so that '--vacuum-time 1s' will take effect. - Actually after 'journalctl --rotate' these annoying logs should have disappeared. So the final answer should be
journalctl --rotate.
P.S. Here are relevant parts of journalctl's help
-N --fields List all field names currently used -F --field=FIELD List all values that a specified field takes --disk-usage Show total disk usage of all journal files --vacuum-size=BYTES Reduce disk usage below specified size --vacuum-files=INT Leave only the specified number of journal files --vacuum-time=TIME Remove journal files older than specified time --verify Verify journal file consistency --sync Synchronize unwritten journal messages to disk --relinquish-var Stop logging to disk, log to temporary file system --smart-relinquish-var Similar, but NOP if log directory is on root mount --flush Flush all journal data from /run into /var --rotate Request immediate rotation of the journal files --header Show journal header information --list-catalog Show all message IDs in the catalog --dump-catalog Show entries in the message catalog --update-catalog Update the message catalog database --setup-keys Generate a new FSS key pairAlsosudo journalctl --vacuum-files 1.
journalctl -b will show only from the most recent boot. You can also use-b -1,-b -2 etc. Your horrendous day is still there but you won't have to see it, unless you need to.
Back it up in case if you need it in future:
cp /run/log/journal/<temp-string>/system.journal /mylog/dir/back/system.journal.bakClear the file:
cd /run/log/journal/<temp-string>/>system.journalCheck to see latest logs:
journalctl -xe
- Clear the file with a
cdcommand?Alexis Wilke– Alexis Wilke2020-11-04 21:39:49 +00:00CommentedNov 4, 2020 at 21:39 - @AlexisWilke The cd command is just to navigate to the directory, the next line is bashism which truncates the size of the file to 0 (this answer assumes the shell used is Bash, and doesn't work with things like zsh)Ferrybig– Ferrybig2021-02-08 13:38:09 +00:00CommentedFeb 8, 2021 at 13:38
- @Ferrybig Ah. Now that the formatting was fixed, I can see how that works. Before those two lines appeared on a single line.Alexis Wilke– Alexis Wilke2021-02-08 18:32:08 +00:00CommentedFeb 8, 2021 at 18:32
I was baking in afactory reset step at the end of a machine image provisioning script.
Ended up using this:
sudo journalctl --relinquish-var --rotatesudo find /var/log -type f -print -delete# very soon after here, shutdown happens & whole-OS machine snapshot is takenThis allows new instances spawned from this image to have logs starting from a clean slate.
So that, e.g.journalctl --list-boots will show only the boots ofthe instance itself — withoutphantom boots from previous life recordedby the image-provisioner instance.
Adding my answer as found none to combine all actions below. On Linux Mint 21 based system to clearall logs I did:
sudo rm -r /var/log/* # to clear all "permanent" logssudo journalctl --vacuum-time=1s # to clear archived logs as per other answerssudo find /run/log -name system.journal -exec dd if=/dev/zero of={} count=0 bs=1 \; # clear current log file similar to @Maxpm answerInterestingly:
- deleting files in
/run/logresulted in some being recreated but w/out access control to allow ordinary users see system entries - so clearing it is. - clearing
system.journaldid not change its size (still 8Mb), butjournalctlstarted to return "no entries". When I tried to first stop systemd journaling service, then clear the file, it became size 0 but reverted to 8Mb right after the service started.
journalctl is aquery command, and it is unnecessary to delete past logs in order to avoid querying them. If you want to start with a clean slate, then query only recent entries, and use the--follow flag to show entries made after you run that command.
journalctl --follow --since="$(date "+%Y-%m-%d %H:%M:%S")"The above command uses the date command to format the current date and time properly for the--since flag to journalctl.
You can also type out some date in the past as a starting point, in case you need to track the logs across a reboot. Run the date command by itself to see the correct format, and make sure to use quotes around the date to avoid parsing issues.
You mustlog in to answer this question.
Explore related questions
See similar questions with these tags.






