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 pre-installed applications that are not used. For example, Wolfram is taking almost 1 GB on the SD card on a fresh installation of Raspberry Pi OS.
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 are looking to quickly progress on Raspberry Pi, you can check out my e-book here. It’s a 30-day challenge, where you learn one new thing every day until you become a Raspberry Pi expert. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.
Free disk space on Raspberry Pi OS with Desktop
If you are lost in all these new words and abbreviations, request my free Raspberry Pi glossary here (PDF format)!
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.
- 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 opt is taking up over 1 GB, and I have no idea what it is.
- By opening this folder, I can see that “Wolfram” is installed.
If I don’t need it, I can uninstall it and save 1 GB.
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.
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.
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 install too many packages that you don’t eventually use.
For example, Wolfram is a package installed by default on 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.
Are you a bit lost in the Linux command line? Check this article first, for the most important commands to remember, and a free downloadable cheat sheet so you can have the commands at your fingertips.
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:
- 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.
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 /
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
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:
At the top, you have the biggest files and folders.
Then, they are sorted by size.
At a glance, you can see that Wolfram, Chromium and LibreOffice are taking a lot of space.
If you don’t need the files, uninstall them :).
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 your system.
Here are a two command options you can try:
- Search for files larger than X:
find <path> -size +<size>
find /home/pi -size +100M
- Search for files with a specific extension:
find <path> -iname *.<extension>
find /home/pi -iname *.mkv
As usual, use “sudo” if you want to search on the entire SD card.
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>
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-11-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.
Sale: 10% off today.
Get the eBook.
Do more with your Raspberry Pi, learn the useful concepts and take the shortcuts.
You miss half of the fun of using a Raspberry Pi if you don’t know anything about Python.
Here is the command to remove all this temporary files:
sudo apt-get clean
And here is the result:
I just save 700M in two seconds :).
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 in my course “The Raspberry Pi Bootcamp“), it will boost the performances, and you’ll never be out of space. My favorite SSD is this one on Amazon, but you can choose any model you like.
Support me: Join the community on Patreon to show your support, get behind-the-scenes content and other awesome perks!
Grab your free PDF file with all the commands you need to know on Raspberry Pi!
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 :).
Raspberry Pi Resources
Not sure where to start?
Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.
Watch the Raspberry Pi Bootcamp course now.
Master your Raspberry Pi in 30 days
Don’t want the basic stuff only? 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.
Download the e-book.
If you just want to hang out with me and show your support, you can also join the Patreon community. I share behind-the-scenes content there and give you early access to my content. You’ll also get a shoutout when you join.
More details here.
Need help building something with Python?
Create, understand and improve any Python script for your Raspberry Pi.
Learn the essentials, step-by-step, without losing time understanding useless concepts.
Get the e-book now.
You can also find all my recommendations for tools and hardware on this page.