Deleting/Clearing systemd journal files, like btmp, and other log files

Deleting/Clearing systemd journal files, like btmp, and other log files

Check and clean log files – /var/log/

To determine the total used space of /var/log/ and /var/log/journal/*/:

Bash
root@server:~# du -hs /var/log/
1.6G    /var/log/
root@server:~# du -hs /var/log/journal/
1.4G    /var/log/journal/
root@server:~#


Display the largest log file of the last 3 months /var/log/journal/*/:

Bash
root@server:~# ls -lath /var/log/journal/*/ | tail -n 3
-rw-r-x---+ 1 root systemd-journal   48M Mar 23 04:05 system@123456xyz.journal


1. Display exact size of the file var/log/btmp in KB.

2. Clear the file /var/log/btmp.

3. Display current size of the emptied file var/log/btmp in KB.

Bash
root@server:~# du --apparent-size /var/log/btmp
15      /var/log/btmp
root@server:~# > /var/log/btmp
root@server:~# du --apparent-size /var/log/btmp
0       /var/log/btmp


Deleting all systemd journal files older than 20 days

Bash
root@server:~# journalctl --vacuum-time=20d
Journal file /var/log/journal/12345/user-1000.journal is truncated, ignoring file.
Deleted archived journal /var/log/journal/12345/system@12345-0123-12345.journal (48.0M).
Deleted archived journal /var/log/journal/12345/system@12345-0123-12345.journal (104.0M).
Deleted archived journal /var/log/journal/12345/user-10008@12345-0123-12345.journal(8.0M).
Vacuuming done, freed 2.7M of archived journals from /var/log/journal/12345.


Deleting all systemd journal files that exceed a disk size of x.

Bash
root@server:~# journalctl --vacuum-size=1G
Deleted archived journal /var/log/journal/12345/system@12345-0123-12345.journal (104.0M).
Vacuuming done, freed 3.9G of archived journals from /var/log/journal/12345.
root@server:~#