You’ve had your Raspberry Pi working away, first as a media center, then a web server with a database, and you’ve been tinkering with lots of other features. But now you’re wondering: what exactly is taking up all your storage space?
Fortunately, when running Raspbian, the Raspberry Pi comes with an excellent command-line tool already installed that makes analyzing disk usage straightforward and intuitive.
Introducing ncdu: NCurses Disk Usage
The ncdu
tool (NCurses Disk Usage) provides an interactive, visual way to explore your Raspberry Pi’s storage. It’s significantly more user-friendly than the standard du
command and allows you to navigate through your directory structure to find space-hogging files and folders.
Basic Usage
To start using ncdu, simply open a terminal or SSH into your Raspberry Pi and type:
ncdu
This command will scan your current directory and all subdirectories, displaying a sorted list of folders by size.
If you want to analyze a specific location, you can provide a path:
ncdu /home/pi
Scanning Only the Root Filesystem
One particularly useful option is to only scan the root filesystem without crossing into other mounted devices (like external hard drives or network shares). This gives you a clear picture of what’s taking up space on your SD card:
ncdu -x /
The -x
flag tells ncdu to stay on one filesystem and not cross filesystem boundaries.
Reading the Display
After scanning, ncdu will show you something like this:
2.6GiB [##########] /usr 1.0GiB [### ] /home 633.8MiB [## ] /opt 593.0MiB [## ] /var 141.4MiB [ ] /lib 10.2MiB [ ] /media 10.1MiB [ ] /mnt 7.9MiB [ ] /bin 7.5MiB [ ] /sbin 6.7MiB [ ] /etc 1.7MiB [ ] /tmp 40.0KiB [ ] /root 16.0KiB [ ] /lost+found 4.0KiB [ ] /srv 0.0 B [ ] /sys 0.0 B [ ] /run 0.0 B [ ] /proc 0.0 B [ ] /dev 0.0 B [ ] /boot
This visual representation makes it immediately obvious where your space is being used. In this example, the /usr
directory is using 2.6GB, while /home
is using 1GB.
Navigating the Interface
Once ncdu is displaying the results, you can:
- Use the arrow keys to move up and down the list
- Press Enter to dive into a directory
- Press Backspace or Left arrow to go back to the parent directory
- Press q to quit the program
This interactive navigation makes it easy to drill down into directories to find exactly what’s consuming your space.
Advanced Features: Exporting Reports
If you want to save your disk usage analysis for later reference or comparison, ncdu allows you to export reports:
ncdu -x -o /home/pi/filesystem.txt /
This command will scan the root filesystem and save the report to /home/pi/filesystem.txt
. Note that this file is in a binary format and isn’t human-readable directly.
To view an exported report later:
ncdu -f /home/pi/filesystem.txt
This feature is particularly useful for:
- Tracking space usage over time
- Comparing before/after a cleanup operation
- Documenting system state before making major changes
When to Use This Tool
The ncdu utility is particularly valuable when:
- Your Raspberry Pi is running low on space
- You’re trying to optimize an SD card with limited capacity
- You suspect log files or cache directories might be filling up
- You need to identify which applications are consuming the most storage
- You’re preparing to back up or clone your system
Conclusion
The ncdu tool provides a user-friendly way to analyse disk usage on your Raspberry Pi. Instead of guessing what might be taking up space or running multiple commands to piece together the information, this single utility gives you a clear, interactive view of your storage situation.
If you’re managing a Raspberry Pi for any length of time, this tool will likely become an essential part of your maintenance routine. Give it a try next time you’re wondering where all your free space has gone!