/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
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.
Then you can check each log size by entering the command
du -sch *.
du -sch *
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
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.
ll the command to view audit logs.
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.
Enter the following command to check the size of logs in sssd.
du -sch *
In the above output, the size of the sssd_nss.log file is more, so you need to clear that log.
> and .log file name to clear audit logs.
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
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.
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?