Managing Logs
Last updated
Last updated
Sometimes if the Linux installation is behaving oddly, it generate a heap of logs. This can quickly fill up your storage space. I encountered this issue when using Linux on android via linuxdeploy.
Here is the command for checking the log size in Linux. This command will list the top 10 log files based on its size (large to small). This is in Debian system.
Output may look like this
You can always open and study the logs to understand the problems. Or you can delete them using this command. Here we are deleting nginx logs with the size 512K.
You can also create a script to automatically delete the log at certain interval, like a day or every 12 hours. Here is an example script file. You can modify the script based on the log files you want to clear.
Place the script file (logerase.sh) at /usr/local/bin.
Give execute permission to the script via this command
Automate the script execution via Crontab
Add the following line in crontab to execute the script daily at 00:00