featured computer 850

Linux Clean Up (Free) System Disk Space

Share page:

Created 2015-08. Xubuntu 14.04.2.

Update 2023

I think this page is deprecated, at least for anyone using a Ubuntu-based Linux distribution. Sometime in the last few years, the automatic software updater started to add a second round of updates after the kernel files were updated. It appears after the restart and shows a window of what will be removed and that “0kb” of space will be used. Yay. One less thing to worry about.

WARNING!

I am NOT a system administrator. I am a home user who can reinstall my operating system as many times as I want. If you are a professional and you follow these steps, then you are an idiot and I cannot help you. If you only want the steps I took, scroll down to the “Procedure” heading.

Background

I still have not found a simple, graphical tool to show the amount of disk spaced used as you browse the system. After over a decade of daily linux use, I’m a little embarassed to say I have Windows Explorer envy! Gnome has a program called Disk Usage Analyzer that sounds very promising, right? When you start it up, however, you get the pic below… This is not a user-friendly GUI by any stretch of the imagination.

disk usage

I have learned a couple of useful command line tools for quickly getting an overview of disk usage, but these are not things I think about running on a regular basis. The command “df -h” will show total, used, and free disk space of a system when no path is specified. This made it clear that the partition was filling up, but still no details. I ended up opening my file browser to “/” and righ-clicking each folder and looking at the properties.

df command

Procedure – The BIG THREE Culprits

I originally thought that 10GB would be plenty for operating system files… and I’m pretty sure I was right. There were GIGABYTES of old modules, kernels, and packages that were, as far as I can tell, not in use for a while. From a top-level investigation, the biggest users of disk space were /usr=4GB, /lib=2GB, and /var=1GB. This is what I deleted. You can use wildcards with rm if you know how. Otherwise, repeat for each directory you want deleted.

Delete all but the latest 3 (do I need more than 1?) linux-headers directories in /usr/src.

me@myhost$ cd /usr/src

me@myhost$ sudo rm -r <linux-headers_#_you_want_gone>

Delete all but the latest 3 linux kernel modules directories in /lib/modules.

me@myhost$ cd /lib/modules

me@myhost$ sudo rm -r <#_linux_kernel_modules_you_want_gone>

For fast internet connections, delete packages used by apt (/var/cache/apt/archives). This means you’ll have to download them each time.

me@myhost$ sudo apt-get autoclean

These procedures reduced my system disk space usage from 97% to 67%.

Notes

Read the warning above and note that I have a SEPARATE PARTITION for operating system files. You can permanently mess up your system by deleting things in these directories. Last warning.

Similar Posts