/var is a standard subdirectory of the root directory in Linux and other Unix-like operating systems that contains files to which the system writes data during the course of its operation.
/var is specific for each computer; that is, it is not shared over a network with other computers, in contrast to many other high-level directories. Its contents are not included in /usr because situations can occur in which it is desired to mount /usr as read-only, such as when it is on a CDROM or on another computer. /usr, which is generally the largest directory (at least on a newly installed system) and is used to store application programs, should only contain static data.
Among the various subdirectories within /var are /var/cache (contains cached data from application programs), /var/games (contains variable data relating to games in /usr), /var/lib (contains dynamic data libraries and files), /var/lock (contains lock files created by programs to indicate that they are using a particular file or device), /var/log (contains log files), /var/run (contains PIDs and other system information that is valid until the system is booted again) and /var/spool (contains mail, news and printer queues).
Follow the below steps to clear /var in Linux:
Before clearing the var partition, enter the following command to see its size. We can see that the var partition is 90% full.
df -Th /var
Output
Filesystem Type Size Used Avail Use% Mounted on /dev/edumotivation/rhel-var ext4 20G 17G 1.9G 90% /var
Let us now check the Logs size in the var partition. To check the log size, enter the command cd/var/log
so that we go to the log path in the var partition.
cd /var/log
Then you can check each log size by entering the command du -sch *
.
du -sch *
output
20G audit 0 boot.log 12G sssd 40K tallylog 2.0M sudo.log 4.0K yum.log
In the above output, the size of the audit
and sssd
the log is more, so you need to clear that log.
First, we will clear the logs in audit, to go to the audit path enter the following cd /var/log/audit
command.
cd /var/log/audit
Enter ll
the command to view audit logs.
ll
Enter rm -rf audit.log*
command to clear audit logs.
rm -rf audit.log*
Now to clear the sssd logs, first enter the following command to go to sssd Path.
cd /var/log/sssd
Enter the following command to check the size of logs in sssd.
du -sch *
Output
12G sssd_nss.log
4.0K sssd_nss.log-20220522.gz
181M sssd_nss.log-20220529
In the above output, the size of the sssd_nss.log file is more, so you need to clear that log.
Enter >
and .log file name to clear audit logs.
> sssd_nss.log
After clearing the var partition, enter the following command to see its size. We can see that 13G space is now available in the var partition.
df -Th /var
Output
Filesystem Type Size Used Avail Use% Mounted on /dev/edumotivation/rhel-var ext4 20G 5.8G 13G 31% /var
That’s all, In this article, we have explained How to clear /var in Linux.
Conclusion
I hope you have learned something from this article.
Now I’d like to hear your thoughts.
Was this guide useful to you?
Or maybe you have some queries.
Have I not included any command in this guide?