The Linux Page

/var is 99% full...

Problem

On Unix systems, you create partitions and assign them a folder such as /usr, /home, and /var. Many people like to put different things on different partitions. Very frankly, it is often complicated to do that, so if you don't have a real need, only break up the /home and /tmp folders from the rest. The /var is a good idea to break up if you use databases or very heavy logs. The /etc can be separate mainly for ease of backup.

Today, I had an error with my mail system and checked my hard drives. I ran df and got the output saying that /var was 99% full. Full of what?!

I checked different folders with du and found out that the /var/cache folder was 9Gb in size. That's about 50% of the partition!!! That's quite a cache alright...

The fact is that what was so large in the folder was the archives folder of the apt cache:

    /var/cache/apt/archives

Solution

I remembered two things in that regard. First the apt-get tool can be setup to not use a cache. So if you do not want the cache at all, you can simply get rid of it altogether (and it won't be recreated, although apt-get still uses some space whenever you upgrade, it releases the space as soon as it is done.)

The other thing is to clean the folder manually with a command as follow:

    apt-get clean
    [WARNING: this cleans EVERYTHING]

This goes through that entire folder and delete everything. Poof!

The apt-get tool is able to re-download anything it needs to, so you can delete everything and you will be just fine.

Another command is used to delete everything that's really not necessary (i.e. older versions of all the packages.) This command is autoclean:

    apt-get autoclean

And that's probably the one you want to run on your system.

In my case, the /var folder went from 99% to 60%. Woof! Saved 39% or about 7Gb of space (and my daily backups will go faster!!! 8-) )