Limpar/Excluir arquivos de systemd journal, como btmp, e outros arquivos de log

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

Controlar e limpar os arquivos de log – /var/log/

Para determinar o espaço total usado de /var/log/ e /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:~#


Mostrar o maior arquivo de log dos últimos 3 meses /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. Exibir o tamanho exato do arquivo var/log/btmp em KB.

2. Limpar tamanho /var/log/btmp.

3. Exibir o tamanho atual do arquivo esvaziado var/log/btmp em 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


Excluir todos os arquivos de diário do systemd com mais de 20 dias.

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.


Excluir todos os arquivos de journal do systemd que excedem um tamanho de disco de 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:~#