Ubuntu log file var/log/syslog.1 fills up space and causes crash

When the computer is running for a long time or large files are deleted, the log files grow wildly, eventually causing the var space to fill up and causing a crash. At this time, remember not to force shutdown , otherwise it will not start. The only way to restore the computer to normal is by deleting the log files. So here comes the question. How to delete the log file when the computer has crashed and the keyboard, mouse, and even the shortcut key "Ctrl+Alt +T" cannot open the terminal? We can restart the computer by sending instructions directly to the kernel, then enter root mode, directly command to delete the relevant log files, and then restart the computer. In this way, the crash problem caused by the log file will be solved. The following operations have been personally tested to be effective.
1. Restart the computer.
If your system is stuck, you can only bypass the system and restart the computer by sending instructions directly to the kernel. The specific operation is as follows:
Insert image description here
If your host can restart normally, congratulations, the operation is over here. But my host cannot restart normally. In this case, you need to enter root mode when restarting.
2. Enter root mode
. When restarting to enter root mode, the actual operation is as follows:
(1) Restart ubuntu, then press and hold shift to enter the grub menu, select the second option Advanced options for Ubuntu
Insert image description here
or your option is "ubuntu advanced options".
(2) Enter the next interface and select recovery mode.
Insert image description here
If your computer is a dual system, there will be four lines here. Just select the second line.
(3) Enter the Recovery Menu and select the root option
Insert image description here
(4) Press Enter to enter the command mode. At this time, you can only view the file and cannot modify it (read-only mode). Execute the command

mount -o remount,rw /

This will enter the root mode of the terminal, where you can modify files, delete files, or restore previously modified files with errors.
3. Delete the log file
(1) Enter the following command to view the log file

du -h --max-depth=1 /var/log/* #需要在root权限下查看 

Return results:

0 /var/log/alternatives.log
...
20G /var/log/kern.log.1
...
4.8G /var/log/syslog.1
...
0 /var/log/yum.log

It can be seen that the files "kern.log.1 and "syslog.1" are already very large and need to be cleaned up. Note that these two files cannot be deleted directly with rm -rf... and need to be cleaned up with fixed instructions.
(2) Input The following command cleans and deletes files under the specified path

echo > /var/log/syslog.1

echo > /var/log/kern.log.1

At this point, these two files have been cleared, and you can restart your computer with peace of mind.
4. Restart the computer
and enter at the root terminal command line:

reboot

Successful restart!

Guess you like

Origin blog.csdn.net/zhangqian_shai/article/details/123948452