Raspberry Pi

How to free up the space on the Raspberry Pi operating system

Raspberry Pi does not come with built-in storage; a microSD card is used to hold the operating system and packages. The SD card can quickly be filled up by the operating system updates and many libraries downloaded with the packages we install. Therefore, unused packages and files should be removed from time to time. This write-up is very useful as different commands to free up the space using the terminal on Raspberry Pi have been explained.

How to find out the details of the used memory on the Raspberry Pi

We will first update and upgrade all the packages of the Raspberry Pi repository by using a command:

$ sudo apt update && sudo apt full-upgrade -y

After making sure all the packages are up to date, we will install a package of “Baobob” that is used to find out the information about the occupied space on the Raspberry Pi:

$ sudo apt install baobab -y

After the successful installation of the “Baobab”, we will launch it using the command:

$ baobab

A graphical interface will be opened with the name of “Devices and Locations”:

In the above output we can see that the total free memory of the Raspberry Pi is 55.6 GB, we will click on the “raspberrypi” to extract the information about the memory:

In the above output we can see different directories are using the memory of the Raspberry pi, now we can see that the “usr” occupied the 3.4 GB space, so we will click on it and find out the files which are using space:

Like this, we can look into every directory and note down the files which are no longer used and can remove them from the Raspberry Pi to free up the space.

How to free up space on Raspberry Pi

We can free up the space by removing the packages from the Raspberry Pi which occupied maximum space and are of no use to us, for example, we want to remove the “VLC media player”, so we will use the following command:

$ sudo apt purge vlc -y

Similarly when we install and delete the packages on the Raspberry Pi, the cache data is stored on the memory and a time comes when it takes a large space on the memory of the Raspberry Pi, in order to clean up the memory from the cache data, use the command:

$ sudo apt-get clean

Similarly, to remove the packages and dependencies of different packages which are not being used from a long time, use the command:

$ sudo apt-get autoremove -y

After running these commands, we will again launch the “Baobab” to confirm whether some memory has been free up or not, we will launch the “Baobab” application by using the command:

$ baobab

And we can see that we have free up about 100 MB space and the available space is updated from 55.6 GB to 55.7 GB:

Conclusion

By downloading different packages on the Raspberry Pi not only occupies the space of the Raspberry Pi but also reduces the efficiency of the CPU. When the Raspberry Pi is switched on, the processor of the CPU loads all the files and programs which makes it slow. In this write-up, we have discussed the methods to free up the space on the Raspberry Pi and also discuss the Baobab utility which is used to monitor the memory statistics of the Raspberry Pi.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.