How to Free Up Space on Ubuntu and Linux Mint

The operating systems become cluttered when several programs are installed. Hence, it is necessary to do a thorough cleaning. There are several ways to free up the space in Ubuntu and Linux systems if you are running out of it. 

ubuntu terminal

Modern Operating Systems like Linux Mint and Ubuntu generate huge amounts of files, logs, archives, and cache. For laptops and machines with old hardware, the HDD and SSD space is essential. Otherwise, they cannot function properly if the space is all filled up. 

In this article, you will learn various ways on how to free up disk space in your Ubuntu and Linux Mint systems. 

Find Out the Free Space on the Ubuntu and Linux Systems

Firstly, you need to find out the free space in your system. For this purpose, you can use a disk analyzer in Ubuntu GUI or check it from CLI. To check space from the Command-line Terminal, you need to run the command given below: 

df -h or ls -lin

This command will give you an overall idea of the occupied space in your system. You can also see it in the image given below:

Free Space on the Ubuntu and Linux Systems

Free Up Space on the Ubuntu and Linux Systems

Now that you know the amount of free space you have in your Ubuntu or Linux systems, you can clean it up. To free up some occupied space in your Ubuntu or Linux, you can use both the command line or GUI options. However, in this article, we will focus on the Terminal options to clean up the space. 

1. Delete the Trash

The first method is to delete the trash. Ubuntu and Linux systems store trash files in a hidden directory. The hidden directory is in your user account at the location ~/.local/share/Trash/files.

Firstly, to check the trash files, type the command given below: 

ls -al ~/.local/share/Trash/files

After that, navigate into the trash directory using the cd command. 

cd ~/.local/share/Trash/files

Finally, you will use the rm command to delete all the trash files.  

rm -rf *

After executing this command, you will find your trash folder empty. 

2. Get Rid of Unused Packages

The second thing you can do to free up space is to get rid of unused packages. For this method, you will use the “autoremove option with the apt-get command. To get rid of the unused packages, execute the command given below: 

sudo apt-get autoclean && sudo apt-get autoremove

This command will remove libs, packages, and old Linux kernel files.

Free Up Space in the Ubuntu and Linux Systems

3. Uninstall Unnecessary Applications to Free Up Space on Ubuntu and Linux

You can remove unnecessary applications that are no longer required. Furthermore, you can uninstall those that you do not use anymore. We use the apt-get command to remove unnecessary applications. Execute the command given below to uninstall unused packages:

sudo apt-get remove package-name1 package-name2

4. Clean Apt Cache

APT (Advanced Package Tool) is used for installing, removing, and managing software on the Ubuntu systems. When performing the operations, it keeps a cache of previously downloaded and installed packages even after you have uninstalled them.

The APT keeps a cache of packages in the/var/cache/apt/archives directory. Over time, this cache can grow quite large. Firstly, you should check the size of the apt-cache. To see the size, use the du command.

sudo du -sh /var/cache/apt 
free up space on ubuntu and linux - clean apt cache

Secondly, you can clean it using autoclean.

sudo apt-get autoclean

Additionally, you can also delete the apt-cache entirely. It will free up more disk space. 

sudo apt-get clean

5. Clear Systemd Journal Logs

The Ubuntu and Linux systems maintain various logs. It can log kernel logging data, system log messages, standard output, and errors. 

Firstly, you will check the size of the systems journal log files. To check the size, you can use the journalctl command.  Execute the command given below, and you will see the log file size:

journalctl --disk-usage
free up systemd journal logs on ubuntu and linux

Secondly, you should clean the log files. The easiest way is to clear the log files that are there for certain days. To do this, execute the command given below:

sudo journalctl --vacuum-time=3d

6. Remove Older Version of Snap Applications

Snap packages are containerized software packages. They are used to install software and applications easily. Snap packages are usually bigger. Firstly, execute the command given below to see the size of the Snap packages.

du -h /var/lib/snapd/snaps
remove older version of snap

Additionally, you can also use the snap list command to view the snap packages. 

Secondly, to remove these packages, you will have to create a new shell script using the touch or nano command. After that, add the lines given below in your shell script. 

set -eu
snap list --all | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
        snap remove "$snapname" --revision="$revision"

Finally, change its execute permission with the chmod command and execute it. 

7. Clean the Thumbnail Cache

Your system probably creates a thumbnail automatically. The thumbnails are created to view the icons in the file manager. It stores those thumbnails in a hidden directory at the ~/.cache/thumbnails location. 

It is crucial to clean up the thumbnails. Otherwise, over time, they occupy a lot of space.  Firstly, you should check the size of the thumbnail cache by using the du command.

du -sh ~/.cache/thumbnails
Clean the Thumbnail Cache

Finally, to delete the thumbnails, use the rm command.

rm -rf ~/.cache/thumbnails/*

8. Remove the Old Linux Kernel Files

When you update your system to a newer version, old Linux kernel files are not deleted. Hence, it is crucial to clean up those files to retain some space in the system.

First, use the following command to list all the current kernel packages that exist in the system.

sudo dpkg –list Linux-image

After that, use sudo apt command to remove the kernel files, just like you would remove any package. 

sudo apt remove linux-image-VERSION

It is crucial to keep the OS free from junk, system logs, and cache application leftovers. These files make a system slow. Hence, they affect the system performance in the long run. 

In this article, we have discussed several ways to free up space in Ubuntu and Linux systems. Regularly following these steps will keep your system free from unnecessary files.

In case of any suggestions or queries, leave a comment below.

If this guide helped you, please share it.

Leave a Reply
Related Posts