DEV Community

Ankur Sharma
Ankur Sharma

Posted on

How to free up space in Ubuntu

Whenever you are running out of disk space on Ubuntu server/desktop , There are several ways to free up space on ubuntu and other linux based systems.

I have listed down some command line tricks here!

1. Check disk space

df -h
Enter fullscreen mode Exit fullscreen mode

Your will get an output that shows the space

Image description

2. Clear APT Cache
Ubuntu keeps a cache of the installed packages which are downloaded or installed earlier even after uninstallation. Cache files in this location /var/cache/apt

To check the disk space consumed you can use the following command.

sudo du -csh /var/cache/apt
Enter fullscreen mode Exit fullscreen mode

Output will be look like

Image description

Now you can clean this cache using the following command.It will clean up entire cache which frees up more space.

sudo apt-get clean
Enter fullscreen mode Exit fullscreen mode

If you wish to clean up only the outdated packages, you can use the following command.

sudo apt-get autoclean
Enter fullscreen mode Exit fullscreen mode

3. Remove unused packages and Kernels

You can remove the kernels & packages that are no longer needed and that are installed from Ubuntu archive while system updates using the following command.
Note: This command will not remove the kernels that are installed manually.

sudo apt-get autoremove --purge
Enter fullscreen mode Exit fullscreen mode

Top comments (0)