Limpar/Excluir arquivos de systemd journal, como btmp, e outros arquivos de log
Carlotta
Controlar e limpar os arquivos de log – /var/log/
Para determinar o espaço total usado de /var/log/ e /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:~#
Mostrar o maior arquivo de log dos últimos 3 meses /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. 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.
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
Excluir todos os arquivos de diário do systemd com mais de 20 dias.
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.
Excluir todos os arquivos de journal do systemd que excedem um tamanho de disco de 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:~#