On Linux systems, the /var/log directory stores important system logs such as authentication, cron jobs, system messages, and web server logs. Over time, these logs can grow large and take up significant disk space.

To manage this, administrators often use scripts to clear or reduce the size of log files. Below is an example script that trims log files while retaining recent entries.

Sample Script to Empty /var/log

#!/bin/bash

logpath=/var/log
loglines=5000

for name in `ls $logpath`
do
tail -n $loglines $logpath/$name > /tmp/log.temp
cp -f /tmp/log.temp $logpath/$name
done
rm -f /tmp/log.temp

/bin/sleep 3
/usr/bin/killall -9 httpd
/bin/rm -rf /usr/local/apache/logs/*
/bin/sleep 5
/etc/rc.d/init.d/httpd startssl

Using scripts to empty or trim /var/log helps manage disk usage and maintain system performance. However, for production servers, it’s recommended to use log rotate or other log management tools to ensure proper rotation and archiving.

Popular Posts You May Read

Explore more hosting insights, tips and industry updates.

Google Crux

What is Google CrUX (Chrome User Experience Report)

Google CrUX is a powerful dataset by Google that provides real user experience data for websites, helping…

Windows vs Linux VPS Hosting – Key Differences and Benefits

VPS is well known as a virtual private server. VPS has a server-splitting process. Each…

Joomla Tutorial: Converting Static Website To Joomla 1.5

This tutorial will help you to convert a static website ( FrontPage/ Dreamweaver) to Joomla…