I have an ubuntu 22.04 LTS, I've notice that i'm running out of memory so I've analized the disk and found a file called /var/log/syslog.1 of 11,5Gb, can i delete it? I also have noticed a backups folder, can i delete them exept for the last one to save space?
-
1Your tag and description of the problem needs to be corrected. A disk is not memory it is hard disk space. The tag memory usage should be removed. If the file is called syslog. 1 , it already was rotated. The currently in-use log file would be syslog . If you don't need it, just delete it. So yes BUT why is it so large, look at what is in the file for clues. – David Oct 02 '22 at 07:01
-
1Perhaps relevant: Very large log files, what should I do? – steeldriver Oct 02 '22 at 12:25
-
1Does this answer your question? Very large log files, what should I do? – Pilot6 Oct 03 '22 at 14:28
1 Answers
In /var/log
you can delete anything ending in a digit or ending in .gz
. All of those are old log files that are made because of a log rotating tool.
Mind though that removing the logs does not fix the reasons for making this log increase. Check the current log for repeating notices or errors and then find a fix for each of them.
You can do that with:
sudo -i
rm /var/log/*[0-9] /var/log/*.gz
If you want to empty the current used log use >
. So with syslog
as an example:
sudo -i
> /var/log/syslog
That will empty syslog
but keep all permissions intact. Not sure if it is still an issue but in the past services would crash expecting a log file to be present when writing to it if that log file was there when the service was started. Using >
prevents that too.
I also have noticed a backups folder, can i delete them exept for the last one to save space?
Unclear. Logrotate does not by itself use backup folders. You will need to check where it originates from. Same rules should apply though: files ending in a digit or in .gz
will be older log files no longer in use.

- 299,756
-
Just deleting log files without checking / pondering on the content first might become a future problem, I suspect. – Hannu Oct 02 '22 at 09:57