There are a few tools at your disposal for checking the disk space on a Raspberry Pi system. These tools and Linux commands can be used to check a storage device’s capacity (such as that of your micro SD card) and the size of the files on it, or just to check the size of a particular directory or file. We will show you how to get a visual representation of how the total storage space is being used on your Raspberry Pi, as well as a few commands that you can enter into the terminal to quickly find the relevant storage stats on your Raspberry Pi.
In this tutorial you will learn:
- How to check Raspberry Pi disk space with Disk Usage Analyzer
- How to check Raspberry Pi disk space with
- How to check Raspberry Pi disk space with
|Requirements, Conventions or Software Version Used
|df, du, Disk Usage Analyzer
|Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Using Disk Usage Analyzer (GUI) on Raspberry Pi
We will start off by showing you how to get a visual breakdown of how the disk space is being used on your Raspberry Pi system. This is helpful in determining which directories on your Raspberry Pi are taking up the most space. It is not uncommon for people to have a bloated directory or two that take up massive amounts of space, so what you find may surprise you.
- First, you will need to install Disk Usage Analyzer by opening a command line terminal and entering the following commands:
$ sudo apt update $ sudo apt install baobab
- Once it is done installing, you can open Disk Usage Analyzer by executing this command in terminal:
- When the program opens, it will ask if you want it to scan the home directory or an entire disk. Make your selection and the utility will begin scanning for files. Once it finishes scanning for content, Disk Usage Analyzer give you a full readout of how your hard disk space is being distributed to various directories on your Raspberry Pi. There is also a graphical representation which you can move your mouse cursor over to get an even better idea. It lists directories by size, so you can quickly determine what is chewing up the most disk space.
Check Raspberry Pi disk space from command line
You can get a quick and concise readout of the hard disk usage on your Raspberry Pi system with the following command:
$ df -h
-h flag tells the command to make the sizes human readable. It is much easier to look at gigabyte values as opposed to bytes. The output from this command is very informative because it also shows us the size of all the mounts on our system; however, this includes psuedo file systems, such as all the tempfs directories in the screenshot above.
An even better way to use the
df command is by specifying the mount point you wish to check. So to check the free space on root, you can use this command:
$ df -h / Filesystem Size Used Avail Use% Mounted on /dev/sda1 125G 7.7G 111G 7% /
df is great for checking disk usage on any mount point for the Raspberry Pi, the
du command complements it by being able to check the storage usage on any directory – and optionally, its subdirectories. For example, here is how we would see how much space our user’s home directory is using:
$ du -sh ~
-s flag in the command tells
du to just return statistics for a single directory, rather than also listing all the subdirectories. The
h flag makes the output human readable, as discussed earlier.
Running the command without the
-s flag is also very helpful, since you can see which subdirectories are taking up a lot of space. Be warned though, the output can be overwhelming if there are a lot of subdirectories, like this:
$ du -h ~
Another handy flag is
--max-depth which tells du how deeply it should traverse into subdirectories. Use it like this (replacing
1 with any number):
$ du -h --max-depth=1 /home/linuxconfig
If you try to run
du on your root directory to see storage space across the entire disk, keep in mind that you will need to execute that command with root privileges and you should redirect standard error to
/dev/null since you’ll get a lot of “permission denied” spam in your output.
$ sudo du -sh / 2> /dev/null
In this tutorial, we saw how to check disk space via GUI and command line on a Raspberry Pi system. Both the GUI and the command line are able to give us a quick summary of storage usage, or detailed breakdowns of how storage space is being used across various directories on our Raspberry Pi. We can always expand the storage on our Raspberry Pi by plugging in USB drives or upgrading to a micro SD card with larger storage capacity.