πŸ’Ύ Linux/Unix: Storage, Archiving & Compression
Estimated reading: 3 minutes 273 views

πŸ’½ Linux/Unix: Disk Usage Commands – df, du Explained with Examples

Introduction – Why Learn Disk Usage Commands in Linux?

Running out of disk space can lead to failed installs, corrupted logs, and halted services. Knowing how to monitor disk usage is essential for maintaining a healthy Linux/Unix system. Commands like df and du help you quickly identify disk space usage by filesystem or directory, so you can clean up and plan effectively.

In this guide, you’ll learn:

  • How to check free and used disk space with df
  • How to find large files and folders with du
  • Real-world examples and practical flags for scripting or analysis

1. df – Display Filesystem Disk Space Usage

What is df?

The df (disk free) command shows used and available space on mounted filesystems.

Syntax:

df [options] [path]

Common Options:

OptionDescription
-hHuman-readable (e.g., MB, GB)
-TShow filesystem type
-xExclude filesystem type
--totalShow grand total summary

Example 1: Show space on all mounted filesystems

df -h

Output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   32G   15G  69% /
tmpfs           1.9G     0  1.9G   0% /dev/shm

Useful for checking overall system usage.


Example 2: Check specific mount point

df -h /var

Example 3: Include filesystem type

df -hT

Output:

Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sda1      ext4   50G   32G   15G  69% /

2. du – Estimate File & Directory Space Usage

What is du?

The du (disk usage) command shows the space used by directories or files, useful for finding large folders.

Syntax:

du [options] [path]

Common Options:

OptionDescription
-hHuman-readable sizes
-sSummarize total only
-aShow all files and subdirs
--max-depth=NLimit recursion depth
--exclude=PATTERNIgnore certain paths

Example 1: Check size of a folder

du -sh /home/user

Output:

2.1G	/home/user

Example 2: Show size of all subfolders in /var

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

Output:

200M	/var/log
3.5G	/var/lib
120K	/var/spool

Quickly locate heavy directories.


Example 3: Find top 10 largest folders

du -ah / | sort -rh | head -n 10

Output:

4.1G	/var/lib/mysql
2.0G	/home/user/Videos
1.5G	/opt/docker/images

Tool Comparison: df vs du

Featuredfdu
Shows usage ofFilesystems (mount points)Individual directories/files
Ideal forChecking total disk spaceFinding space hogs
Default unitKB (use -h for human-readable)KB (use -h)
Recursion

Summary – Recap & Next Steps

The df and du commands are essential tools for disk space auditing, cleanup planning, and managing storage resources on Linux systems. Use them regularly to monitor space usage, prevent full disks, and optimize performance.

Key Takeaways:

  • Use df -h to see how much space is left on mounted filesystems.
  • Use du -sh to check how large a folder is.
  • Combine du with sort to find large directories consuming space.

FAQs

Why does du and df show different values?
df checks free space on the filesystem level; du scans actual file sizes. Differences may include reserved space or open-but-deleted files.

How to find large files using du?
Try:

du -ah / | sort -rh | head -n 10

How do I check disk usage on a mounted USB drive?
Use:

df -h /mnt/usb

Can I exclude certain folders from du?
Yes:

du -h --exclude=/home/user/.cache /home/user

Is there a GUI alternative to du?
Yes, tools like baobab or ncdu (CLI visual tool) offer easier views.


Share Now :
Share

πŸ”΅ Linux/Unix: Disk Usage (df, du)

Or Copy Link

CONTENTS
Scroll to Top