How to Check Disk Space and Usage in Linux Terminal

When working on a Linux server or desktop, you will inevitably need to check how much storage space you have left, or figure out which specific directories are consuming all your disk space. Unlike graphical operating systems, doing this efficiently in Linux requires the command line.

Thankfully, Linux comes with two incredibly powerful, built-in utilities for this exact purpose: df (disk free) and du (disk usage). Here is how to use them to manage your storage.

Checking Overall Disk Space with the “df” Command

The df command displays the amount of available and used disk space on all mounted file systems. It gives you a high-level overview of your entire system’s storage.

If you run df by itself, it outputs storage in 1K blocks, which is very difficult to read. The best way to use it is with the human-readable flag.

  1. Open your terminal.
  2. Type the following command and press Enter:
df -h

The -h flag tells Linux to output the sizes in Megabytes (M), Gigabytes (G), and Terabytes (T). You will see a list of filesystems, total size, used space, available space, the percentage used, and where the drive is mounted (e.g., / for your root directory).

If you want to check a specific filesystem type (like ext4), you can use the -t flag:

df -ht ext4

Finding What is Taking Up Space with the “du” Command

While df tells you that your drive is full, it doesn’t tell you why. For that, you need the du command, which estimates the file space usage of specific directories and files.

If you run du by itself, it will list the size of every single file in your current directory, which will instantly flood your terminal screen. Instead, use these specific combinations:

1. Check the Total Size of a Specific Directory

To see the total combined size of a folder (for example, /var/log), use the -s (summarize) and -h (human-readable) flags:

du -sh /var/log

2. Find the Largest Folders in a Directory

If you are in your home directory and want to see the sizes of the folders immediately inside it (without listing every file deep within them), use the max-depth flag:

du -h --max-depth=1

This will print a clean list of all subdirectories in your current location alongside their sizes.

3. Sort Directories by Size to Find the Culprit

The most useful storage troubleshooting command in Linux involves combining du with the sort command. To list the top 10 largest directories in your current location, run this:

du -h --max-depth=1 | sort -hr | head -n 10

Here is what this command does:

  • du -h --max-depth=1 gets the human-readable sizes of immediate subfolders.
  • | (the pipe symbol) passes that output to the next command.
  • sort -hr sorts the list in reverse order (largest to smallest) using human-readable number parsing (so 2G appears above 900M).
  • | head -n 10 restricts the final output to only show the top 10 results.

By using df -h to monitor your overall capacity and then running the sorted du command inside large directories, you can quickly hunt down and remove bloated log files, old backups, or oversized media files taking up your Linux server’s storage.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.