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/*/:

Shell-Script
  1. root@server:~# du -hs /var/log/
  2. 1.6G /var/log/
  3. root@server:~# du -hs /var/log/journal/
  4. 1.4G /var/log/journal/
  5. root@server:~#


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

Shell-Script
  1. root@server:~# ls -lath /var/log/journal/*/ | tail -n 3
  2. -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.

Shell-Script
  1. root@server:~# du --apparent-size /var/log/btmp
  2. 15 /var/log/btmp
  3. root@server:~# > /var/log/btmp
  4. root@server:~# du --apparent-size /var/log/btmp
  5. 0 /var/log/btmp


Deleting all systemd journal files older than 20 days

Shell-Script
  1. root@server:~# journalctl --vacuum-time=20d
  2. Journal file /var/log/journal/12345/user-1000.journal is truncated, ignoring file.
  3. Deleted archived journal /var/log/journal/12345/system@12345-0123-12345.journal (48.0M).
  4. Deleted archived journal /var/log/journal/12345/system@12345-0123-12345.journal (104.0M).
  5. Deleted archived journal /var/log/journal/12345/user-10008@12345-0123-12345.journal(8.0M).
  6. 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.

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