I am running a small Ubuntu server that I have just given 8GB of virtual HD space. I thought that would be enough. However, as I was trying to transfer some data to it I ran out of space. This left me wondering what happened.
I went to search where the data was stored and it was in /var/cache/apt. It contained 560MB. This is what I did to clean it.
# sudo apt-get autoclean Reading package lists... Done Building dependency tree Reading state information... Done Del libapt-inst1.4 0.8.16~exp12ubuntu10.5 [99.8 kB] Del linux-image-server 126.96.36.199.36 [2,652 B] Del linux-headers-virtual 188.8.131.52.36 [2,642 B] Del perl 5.14.2-6ubuntu2.1 [4,416 kB] Del libapt-pkg4.12 0.8.16~exp12ubuntu10.5 [939 kB] Del perl-modules 5.14.2-6ubuntu2.1 [3,396 kB] Del firefox-locale-en 17.0+build2-0ubuntu0.12.04.1 [482 kB] Del perl-base 5.14.2-6ubuntu2.1 [1,498 kB] Del apt 0.8.16~exp12ubuntu10.5 [1,100 kB] Del linux-libc-dev 3.2.0-33.52 [867 kB] Del linux-headers-server 184.108.40.206.36 [2,648 B] Del apt-utils 0.8.16~exp12ubuntu10.5 [190 kB] Del coreutils 8.13-3ubuntu3.1 [2,216 kB] Del apt-transport-https 0.8.16~exp12ubuntu10.5 [16.3 kB] Del linux-server 220.127.116.11.36 [1,728 B] Del firefox-locale-en 16.0.2+build1-0ubuntu0.12.04.1 [481 kB]
Cache reduced a little bit to 545MB, clearly that was not what I was looking for. Time to wipe out the cache!
sudo apt-get clean
Almost enough space now, but not quite. What else was taking up space. The /usr/src contained 1.2GB of linux headers of all previous kernels that were installed.
Then I came across this post by Ubuntu Genius where he gave this nice one line command:
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
sudo apt-get remove --purge $(dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d')
Just make sure you have rebooted since your last kernel upgrade!
This cleared another 2.5GB!!!!