Ubuntu - Clean up the old updates and recover the storage space
Published on: 22nd Apr 2014
Updated on: 2nd Aug 2025
Why cleanup
The more updates that you have done to the server, the more storage space the old stuff will occupy. To prevent running out of disk space, it's best to do cleanup once a month.
Another area that will occupy lots of space is the logs.
How to find out the storage usage
There are 3 commands that can help in finding out the storage capacity and usage:
-
df
- is a built-in utility for viewing the file system capacity and usage.For example,
df -H
will show the usage statistics in the file system and the size will be shown in 'Human readable' format.Sample output:
Filesystem Size Used Avail Use% Mounted on tmpfs 101M 1.1M 100M 2% /run /dev/vda1 25G 4.0G 21G 16% / tmpfs 505M 1.1M 504M 1% /dev/shm tmpfs 5.3M 0 5.3M 0% /run/lock /dev/vda16 924M 118M 742M 14% /boot /dev/vda15 110M 6.4M 103M 6% /boot/efi tmpfs 101M 13k 101M 1% /run/user/1000
-
du
- is a another built-in utility for listing the directory or file storage usage. It is useful to find out which directory or file that occupied most spaces. -
ncdu
- a nice and beautiful utility program that shows the capacity and usage for the sub-directories but it requires to install.To install this utility before using it.
sudo apt install ncdu
To view the space that has been occupied by the sub-directory at the current directory, run the following command:
ncdu
Then, an intuitive and beautiful result will appear. To find out why a directory is occupying so much space, you may use arrow key to choose the directory and then hit Enter key to drill into that directory.
To cleanup the files created by installation or upgrade
-
Cleanup the unused components and it will recover some spaces,
sudo apt --purge autoremove
-
Other arguments that do partial of the cleanup,
sudo apt-get clean sudo apt-get autoclean sudo apt-get autoremove # '-p' is priority and '-phigh' means set to high priority. sudo dpkg-reconfigure -phigh
Related posts
Back to #UBUNTU blog
Back to #blog listing
Author
Lau Hon Wan, software developer.