Managing disk space is crucial for ensuring the optimal performance of a Linux system. Running out of disk space can lead to critical failures, including system crashes and service downtime. Therefore, regularly checking the available free disk space is an essential task for system administrators and users alike.

In this guide, we’ll explore various methods to check free disk space on Linux. We’ll cover tools such as df, du, lsblk, ncdu, and others, along with practical examples to help you monitor disk usage effectively.

Method 1: Using the df Command

The df (disk free) command is one of the most commonly used tools to check disk space on Linux. It provides a quick overview of the disk usage for all mounted file systems.

Basic Syntax of df:

df [options] [file]

By default, df displays the disk space usage for all mounted file systems.

Example: Display Free Disk Space

df -h

Output:

Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           798M   11M  787M   2% /run
/dev/sda1        50G   20G   28G  42% /
tmpfs           3.9G   44K  3.9G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/sdb1       100G   75G   25G  75% /data

Explanation:

  • Size: Total size of the file system.
  • Used: Amount of space used.
  • Avail: Available free space.
  • Use%: Percentage of space used.
  • Mounted on: The file system’s mount point.

Method 2: Using du to Check Directory Usage

The du (disk usage) command shows the space used by files and directories.

1. Check Space Usage of a Specific Directory

du -sh /var/log

Output:

500M    /var/log

2. Display Disk Usage of Subdirectories

du -h --max-depth=1 /home

Output:

4.0K    /home/lost+found
12G     /home/user1
8.0G    /home/user2
20G     /home

This will shows disk usage for each top-level subdirectory inside /home.

Method 3: Using lsblk for Block Device Information

The lsblk (list block devices) command provides detailed information about all block devices, including disk space and partitioning. While it does not directly show free space, it is useful for understanding how disks are partitioned.

lsblk

This shows the block devices, their sizes, and their mount points. It’s useful for visualizing how storage is allocated across different partitions and disks.

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0    50G  0 disk 
├─sda1   8:1    0    50G  0 part /
sdb      8:16   0   100G  0 disk 
└─sdb1   8:17   0   100G  0 part /data

Method 4: Using df with File Systems

Sometimes, you might want to check the available space for specific file systems or partitions. You can do this by specifying the file system as an argument to df.

Example: Check Free Space for /home

df -h /home

Output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   30G   20G  60% /home

This command shows disk usage for the /home directory.

Method 5: Monitoring Disk Usage in Real-Time

For real-time monitoring of disk usage, you can use watch in combination with df to keep an eye on free disk space as it changes.

watch -n 5 df -h

Explanation

  • watch -n 5: Runs the df -h command every 5 seconds and updates the output in the terminal.

Conclusion

Monitoring disk space is a critical task in Linux system administration. By using tools like df, du, and lsblk, you can effectively track disk usage, identify potential issues, and manage space efficiently. Checking available free disk space on Linux is effortless with dedicated server hosting from Atlantic.Net!