Accessing and Monitoring Your Raspberry Pi’s Hard Drive from the Terminal

Learn how to check raspberry pi storage using command line tools, allowing you to monitor your device’s hard drive usage and manage files with ease. …


Updated August 7, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


Learn how to check raspberry pi storage using command line tools, allowing you to monitor your device’s hard drive usage and manage files with ease.

The Raspberry Pi is a versatile single-board computer that can be used for various tasks like media centers, web servers, or even as the basis of a robotics project. One of the most important aspects of any Raspberry Pi project is managing storage space. This article will show you how to check your Raspberry Pi’s storage using command line tools, allowing you to monitor your device’s hard drive usage and manage files with ease.

Accessing Your Raspberry Pi’s Storage Devices

To start checking your Raspberry Pi’s storage, open up the terminal by pressing Ctrl + Alt + T or searching for “Terminal” in the application menu. In this article, we will be using command line tools to get information about your Raspberry Pi’s storage devices and their usage.

First, let’s list all available block devices on our system:

lsblk

This command will show you a list of all the storage devices connected to your Raspberry Pi, including any SD cards or USB drives. The output will look something like this:

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    15G  0 disk 
└─sda1        8:1    15G  0 part /media/pi/RPI_DATA
mmcblk0     179:0    14G  0 disk 
├─mmcblk0p1 179:1   256M  0 part /boot
└─mmcblk0p2 179:2   13.8G  0 part /

In this example, we can see that there are two storage devices connected to our Raspberry Pi: /dev/sda (an external hard drive) and /dev/mmcblk0 (the internal SD card). The lsblk command provides us with useful information such as the device name, size, mount point, and more.

Checking Storage Usage

Now that we know which devices are available on our Raspberry Pi, let’s check how much storage space is used and available. We can use the df command to do this:

df -h

The -h flag tells the df command to display sizes in human-readable format (e.g., GB instead of bytes). The output will look something like this:

Filesystem      Size  Used Avail Use% Mounted on
/dev/mmcblk0p2  13G  6.8G  5.7G  54% /
devtmpfs        15G     0   15G   0% /dev
tmpfs          15G     0   15G   0% /dev/shm
tmpfs           3G  296K  3.0G   1% /run
tmpfs          15G     0   15G   0% /sys/fs/cgroup
/dev/sda1       14G  8.5G  4.7G  63% /media/pi/RPI_DATA

This output shows us that our SD card (/dev/mmcblk0p2) has 13GB of storage space, with 6.8GB used and 5.7GB available (54% usage). Our external hard drive (/dev/sda1) has 14GB of space, with 8.5GB used and 4.7GB available (63% usage).

Monitoring Storage Usage in Real-time

If you want to monitor your Raspberry Pi’s storage usage in real-time, you can use the watch command in combination with df -h:

watch df -h

This will continuously display the output of df -h, updating every 2 seconds (the default interval). You can change the refresh rate by adding a custom interval value after the watch command:

watch -n 5 df -h

In this example, the output will update every 5 seconds. Press Ctrl + C to stop monitoring storage usage.

Managing Files from the Command Line

Once you know how much space is being used on your Raspberry Pi’s storage devices, you may want to manage files and folders. Here are some common commands that can help:

  • List all files and directories in a folder: ls
  • Create a new directory: mkdir directory_name
  • Remove an empty directory: rmdir directory_name
  • Remove a file: rm filename (use with caution!)
  • Move or rename a file: mv old_filename new_filename
  • Copy a file: cp original_file copy_of_original_file

These are just a few examples of the many commands available for managing files from the command line. With practice, you can become very efficient at navigating and manipulating your Raspberry Pi’s storage using only the terminal.