free disk space on raspberry pi

How to Free Disk Space on Raspberry Pi OS? (Desktop or Lite)

If you click our links and make a purchase, we may earn an affiliate commission. Learn more

SD cards sizes are not (yet) unlimited. If you have a small SD card or are trying many things, you’ll probably run out of space quickly. In this tutorial, I’ll show you how to find what takes up space on your SD card and how to remove it when possible.

The best way to free up space on Raspberry Pi is to uninstall applications that were pre-installed or manually installed but are no longer in use. Total used space can add up quickly with useless software and temporary files.

You’ll find two parts in this guide, one for each Raspberry Pi OS version (Desktop or Lite).
You can absolutely follow the Raspberry Pi OS Lite procedure on Desktop if you prefer.

If you’re feeling lost in all the Raspberry Pi jargon, I’ve got something to help you out. I’ve created a free glossary that explains all the essential terms and abbreviations in a way that’s easy to understand. It’s a great resource to have by your side. Get your free copy here.

Free disk space on Raspberry Pi OS with Desktop

On the desktop version of Raspberry Pi OS, there are a few tools that can be installed to quickly find what use the most disk space on the SD card. The procedure will look like this:

  • Install a tool like Baobab to find the largest files on the SD card.
  • Remove the corresponding files when possible.
  • Uninstall the unnecessary applications that take too much space.

Find the large files on Raspberry Pi OS with Desktop

If you have a desktop environment, you are lucky, no need to use command lines, we can install a tool to help us find the large files on the system. A tool I like, with a name easy to remember, is Baobab.

Install Baobab

  • You can install it graphically by going into the Main Menu > Preferences > Add/Remove Software.
  • Type “baobab” in the search engine on the left.
  • Check the box corresponding to the Baobab package.
  • Click “Apply” to install it.
    Enter your password to confirm the installation.

That’s it! Baobab is ready to use.

Start and use Baobab (Disk Usage Analyzer)

The tool is now available in the Main menu:

  • Open the software by clicking on System Tools > Disk Usage Analyzer.
  • Select the folder to scan (probably /, so the second one).
  • The software will scan your SD card and display the results with a chart like this:
  • On the left, you can see a list of the folders in the selected path (/ in my example).
    For each folder, you have the total size in the second column. And you can click on the left arrow to browse inside each folder and see the details.
  • On the right, there is a graphical visualization of the SD card usage.
    If you prefer, you can click on the icon under the graphic to switch to an alternate view:
    This allows you to quickly locate the largest folders on your SD card.
    For example, in my case I see that the biggest folder is /usr, taking up over 4 GB, and I have no idea what it is.
  • By opening this folder, I can see the details and drill down to better understand what’s going on. I’m on a fresh installation for this test, so I don’t have anything large installed, and the largest folder is simply where the system keeps the downloaded packages during the updates.

Remove files and packages to free up space

Once you know what is taking too much space on your SD card, you can analyze it and remove any unnecessary files.

How to remove files on your Raspberry Pi

The first possibility is to remove files completely.
For example, you may have old files in your Downloads folder.

Something not working as expected?
You can get answers from real experts in minutes.
Get help with your setup

To do this, open the file explorer, go to Downloads and remove the unneeded files (press DEL or do a right-click > Move to Wastebasket).
Don’t forget to empty the wastebasket on the desktop after doing this.

Click on Move to wastebasket

Note: If you don’t have the permission to remove a file, you can use the command I gave in the Raspberry Pi OS Lite part. Just open a terminal and type the commands.

How to remove applications on Raspberry Pi OS

It can also be that you installed too many packages that you don’t eventually use, especially if you started with the Full version of Raspberry Pi OS.
If you don’t need the files, you can remove it in the Add/Remove Software tool.

I already wrote a tutorial about this topic. If you need help, check it out here: How to uninstall programs on Raspberry Pi?.

That’s it for Raspberry Pi OS Desktop. Basically, finding the biggest files and removing them should do the trick (either directly or via the add/remove software tool if it’s an app).

Free disk space on Raspberry Pi OS Lite

On Raspberry Pi OS Lite, you don’t have a fancy graphical tool to find and remove files the same way :). But you can use many commands that will often be faster to use, if you know how to use them.

Tip: Command lines can be a pain to memorize. I put the essential Linux commands on a printable cheat sheet so you don't have to keep googling them. You can grab the PDF here if you want to save some time.

Find the largest files with a command line

There are several commands that can be used on Raspberry Pi to find what take space on the SD card:

Recommended next step
Master Raspberry Pi in 30 Days

If you want a clearer path than jumping from tutorial to tutorial, my book gives you a step-by-step roadmap to really understand your Raspberry Pi.

Check the book here
  • df: to show the disk usage summary.
  • du: to get the disk usage for a specific folder.
  • tree: to analyze the sub-folders.
  • find: to list the biggest files.

Disk usage

The first command you’ll probably need, is “df”.

df is a tool that you can use to display the disk summary.
It will show you a list of partition with several columns:

  • Filesystem: basically the partitions, on Raspberry Pi you have generally / and /boot
  • 1K-blocks: It represents the total size available on this partition
  • Used: the disk space currently used
  • Available: the available disk space
  • Use%: the percentage of use
  • Mounted on: the real location of the partition on the system

To get a more readable display, you can add the -h option like this:

If you want, you can also specify the partition, like this:
df -h /

Analyze sub-folders

Once you know what is the partition to analyze, you can go deeper, and check folder by folder.
To do this, you can use the “tree” command:
tree -dh --du

Don’t forget to use “sudo” in system directories

It’s not perfect. If you have many folders and subfolders, it can be difficult to find the biggest folder which may be an issue.
But, it’s a good tool that you can use once you know approximately where the problem is.

The next command may help you find the specific folder to analyze.

Find the biggest files in a specific folder

Ok, it’s a warrior command here, but it’s very useful.
I’m using it almost every week, and I’ve saved myself a lot of time since I’ve known it.
So, I’ll share it with you here.

“du” is a popular command on Linux to list all the files and folders in a specific folder.
The problem is almost the same as with “tree”, as you will need to scroll many files to find what you are looking for (and the display is not optimal).

Anyway, the idea here is to combine 3 commands:

  • du: to display all the files and folder.
  • sort: to sort the result by size.
  • head: to display only the top 100 of the biggest files.

The command looks like this:
du -ak | sort -nr | head -100

And the result is perfect:

You can use it on the entire partition
Same thing, you need to use sudo to get all the information

At the top, you have the biggest files and folders.
Then, they are sorted by size.

At a glance, what folders or apps are taking a lot of space.
If you don’t need the files, remove them or uninstall the corresponding packages :).

Find files by names or sizes

Finally, the last command I use regularly is “find”.
Like the name suggests, “find” is a command to search for specific files on your system.

Here are a two command options you can try:

  • Search for files larger than X:
    find <path> -size +<size>
    Example: find /home/pi -size +100M
  • Search for files with a specific extension:
    find <path> -iname *.<extension>
    Example: find /home/pi -iname *.mkv

As usual, use “sudo” if you want to search on the entire SD card.

Remove them

Once you know which files are taking too much space, you can remove them if you don’t need them.

Remove the file

The first idea is to remove the files.
Basically, you can delete all the files in your user folder, if you don’t use them.

The command to do this is:
rm <file> or rm -rf <folder>
Example:
rm /home/pi/Pycharm.tar.gz

Even if it’s not recommended removing system files like this, don’t forget to add sudo at the beginning to remove a file where you don’t have the permission. For example:
sudo rm /var/log/syslog.1

Uninstall a package

The second option is to uninstall a package.
You can use apt to do this
, for example:
sudo apt remove openjdk-17-jdk

If you have any question about this, you can check my tutorial on how to uninstall packages.

Clear the APT cache

And the last one is a bonus, that can often save you from a full SD card issue.

When your SD card is full, you can’t use most of the previous commands.
They need a minimum disk space to run (for example the “du” command uses a cache file to store all the results before sorting it by size).

What you can often try, is to remove the apt cache.
When you install a package, Raspberry Pi OS will download it locally before installing it.

Here is the command to remove all this temporary files:
sudo apt clean

And here is the result:

I just saved 100M in two seconds :).

Related: How To Use ‘apt’: The Complete Linux Command Guide

What to do if nothing works?

Generally, you will find a solution by using all the techniques and commands I gave you in this tutorial.
But sometimes, it’s just not possible to save enough space on the disk.

If you are using too much of your SD card, you may need to consider changing it to a bigger one.
You can find my recommendations on my recommend product page.
SD cards are cheap now. I’m using 32 and 64 GB SD card and I have no disk space issues on it.

If you are doing so, you may wonder how you can reinstall everything quickly?
If you are moving from an SD card of 2 GB to 32 GB for example, you can create an image of the 2 GB SD card and flash it on the 32 GB.
Then, expand the main partition to 32 GB, and you’ll quickly get the same system :).

I explain everything in this tutorial: How to back up and restore your Raspberry Pi (part 3).

In fact, the ultimate solution would be to use a USB drive instead of a SD card, as it’s now supported by the Raspberry Pi. Ideally, install the operating system on a SSD (I explain everything here), it will boost the performance, and you’ll never be out of space. My favorite SSD is this one on Amazon, but you can choose any model you like.

FAQ

How to I check free space on my Raspberry Pi?

On a Desktop version, open a file explorer and click on “Filesystem root” on the top left of the screen. The available disk space will be shown in the bottom-right corner. Another solution is to use the command “df -h” and look at the “Avail” column.

How big of a SD card do I need on Raspberry Pi?

As a general rule, an 8 GB SD card is the minimum requirement to install Raspberry Pi OS. If your usage implies to install heavy applications or to store big files, a 32 GB SD card should be enough in most cases.


🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Stuck on this project? Ask me or other Pi users in the RaspberryTips Community. We help each other out and you'll get answers quick. Join and fix it together.

Conclusion

That’s it! You now know how to solve your disk space issue on Raspberry Pi.
Most of the time, some cleaning will be enough to find a solution.
And in most complex situations, you can always create an image of your SD card and flash it on a larger one (as explained here).
I’m sure you’ll find a way :).

Whenever you’re ready, here are other ways I can help you:

Test Your Raspberry Pi Level (Free): Not sure why everything takes so long on your Raspberry Pi? Take this free 3-minute assessment and see what’s causing the problems.

The RaspberryTips Community: Need help or want to discuss your Raspberry Pi projects with others who actually get it? Join the RaspberryTips Community and get access to private forums, exclusive lessons, and direct help.

Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.

Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.

Master Linux Commands: Overwhelmed with Linux commands? This book is your essential guide to mastering the terminal. It includes practical tips, real-world examples, and a bonus cheat sheet to keep by your side.

You can also find all my recommendations for tools and hardware on this page.

Similar Posts

Leave a Reply

Community members only
Comments are reserved for RaspberryTips Community members. Join the community to ask questions, get help, and interact with other Raspberry Pi users.

Join the community  or  log in