How to limit journals to 7 days?

For a normal privat user as me the journals take too much free space, so i asked ChatGPT to give me a one line command to restrict journal logs to 7 days:

And here it is:

Please insert the line to a TextEditor first and copy it from Editor again before you use a terminal. Must be some strange characters there otherwise !!!

sudo sed -i '/^#\?MaxRetentionSec=/d; $aMaxRetentionSec=7d' /etc/systemd/journald.conf && sudo systemctl restart systemd-journald.service && cat /etc/systemd/journald.conf|grep -i MaxRetentionSec=7d

Got it today, so untested until April 13 :slight_smile:

How do i insert such a one liner so user can copy it by click on an visible button?

I don’t really understand your question. The command you issued made a modification to /etc/systemd/journald.conf, so no further action is needed.

And if someone wants to copy that command, hovering their mouse over the top right corner of the box in your post will allow them to copy the whole command to their clipboard with a single click.

:man_shrugging:

Top right corner … thats the answer, thank you!

Did this work properly though?
It would delete a line starting with #?MaxRetentionSec= as the ? is escaped.

What ChatGPT tells in german what the code is doing


Dieser Einzeiler löscht die Zeile, die mit MaxRetentionSec= oder #MaxRetentionSec= beginnt, und fügt dann eine neue Zeile hinzu, die MaxRetentionSec=7d enthält. Die Option ^#\? in der ersten Hälfte des sed -Befehls macht das Muster #MaxRetentionSec= optional, sodass sowohl MaxRetentionSec= als auch #MaxRetentionSec= passen. Der $a -Befehl in der zweiten Hälfte des sed -Befehls fügt die neue Zeile am Ende der Datei hinzu. Anschließend wird Systemd neu gestartet, um die Änderungen zu übernehmen. Beachten Sie, dass Sie Administratorrechte benötigen, um diesen Einzeiler auszuführen.


I opened a changed config, looks ok!!

Tried the sed command sans -i, output does indeed look correct.

This part may be removed, since you know it works.
cat /etc/systemd/journald.conf|grep -i MaxRetentionSec=7d

But i’m wondering how to tell a command that stays plain text if i insert it in

No PLain text after insert ?!!

Format with markdown syntax, if that is what you mean.
Single backticks for `inline code`, or three for a
```
block
item.
```

And now you have to deal with /etc/systemd/journald.conf.pacnew every time you update systemd package.

I’d rather do it the smart way, regardless of future changes:

$ cat /etc/systemd/journald.conf.d/override.conf
[Journal]
MaxRetentionSec=7d
4 Likes

Good advice, i’ll try that:

 Those drop-ins have higher precedence and override the main configuration file. Files in the *.conf.d/ configuration subdirectories are sorted by
1 Like

It’s a bit unsettling how well chatgpt handles obscure things like this. Won’t be long before it learns overrides instead of the “standard” way of editing the config file directly.

There is a short description in the header of /etc/systemd/systemd.conf
Reading is helpful - I had to learn this short time before… :innocent:
Edited…

1 Like

I think you are talking about:

/etc/systemd/journald.conf

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.