Blog / How to check disk space in Linux with df and du

How to check disk space in Linux with df and du

by SW Team

In the Linux environment, keeping track of disk space usage is crucial for effective resource management. Two of the most commonly used tools for this task are df and du. These commands provide valuable information about disk space usage, and understanding how to interpret their output is essential for any user or system administrator. In this post, we will explore how to use these commands, with a special focus on their "human-readable" (-h) versions.


1. The df command

The df (disk free) command is used to get a report of the total, used and available space on mounted file systems. To make the output more readable, you can use the -h (human-readable) option, which displays sizes in more understandable units (KB, MB, GB).

Basic Syntax:

df -h

Typical Exit:

Filesystem Size Used Avail Use% Mounted on
udev 7.8G 0 7.8G 0% /dev
tmpfs 881M 788K 880M 1% /run
/dev/xvda3 28G 19G 7.2G 73% /
tmpfs 4.3G 0 4.3G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 4.0G 9.6M 4.0G 1% /tmp
/dev/xvda1 447M 57M 362M 14% /boot
tmpfs 881M 0 881M 0% /run/user/0

Explanation of Columns:

  • Filesystem: The name of the storage device.
  • Size: Total capacity of the filesystem.
  • Used: Used space.
  • Avail: Available space.
  • Use%: Percentage of space used.
  • Mounted on: Mount point on the file system.


2. The du command

Unlike df, the du (disk usage) command is used to estimate the disk space usage of the specified file or directory. Like df, du can use the -h option to display the information in human-readable format.

Basic Syntax:

du -h /path/to/directory

Typical Exit:

Size Directory
1.5M /home/user/Documents
500K /home/user/Downloads

Exit Explanation:

  • Size: Displayed at the beginning of each line, representing the space used by the directory or file.
  • Path: The specific location of the directory or file.

Interpretation and Practical Use

What to look for?

  • In df, look for mount points near 100% usage, as this indicates that they are nearly full.
  • In du, identify directories that take up an unusually large amount of space, which might suggest a need for cleanup or reorganisation.

Additional Tips:

  • For further analysis, du can be combined with other commands such as sort to sort directories by size:

  • du -h | sort -h

  • Use df regularly to monitor filesystems, especially in production environments where free space is critical.

In summary, df and du are powerful tools for disk space management in Linux. Knowing how to correctly interpret their output can help prevent space problems and keep your system running smoothly.