Use df to check filesystem capacity and du to investigate the space used by directories. Open a terminal or connect to your Linux server using SSH.

What are the du and df commands?

  • df reports used and available space for mounted filesystems.
  • du estimates the disk space used by files and directories it can access.

They measure different things. Their totals do not always agree, particularly when files are open after deletion, permissions prevent a complete scan or filesystem accounting includes reserved space and metadata.

How to use the df (Disk Free) command?

Check filesystem usage with readable units:

df -h

Read Size, Used, Avail, Use% and Mounted on for the relevant filesystem. The -h option uses powers of 1024, so a displayed G represents a gibibyte rather than a decimal gigabyte.

Check inode usage:

df -i

An inode shortage can prevent new files from being created even when free disk space remains. Some filesystems report inode statistics differently.

How to use the du (Disk Usage) command?

Replace the example path with the directory you want to check:

du -sh /path/to/directory

The -s option gives a summary; -h displays readable units. To summarise the current directory, run:

du -sh .

To show directory totals throughout a tree, use:

du -h /path/to/directory

This does not list every individual file by default. Add -a if you also need file entries.

Practical examples

On systems with GNU coreutils, compare /var and its immediate subdirectories, largest first:

du -h --max-depth=1 /var | sort -hr | head -n 20

The parent directory’s total is included. Permission errors can make results incomplete; use administrative access only where you are authorised to inspect those files.

Check space on the filesystem containing /var:

df -h /var

Tips for monitoring disk usage

  • Check both free space and inodes when investigating a full filesystem.
  • Limit directory scans to the relevant location; scanning the whole server can generate substantial disk activity and cross mounted filesystems.
  • Investigate retention and log rotation before removing logs or application data.
  • Monitoring commands report usage; they do not free space or configure automatic alerts.