Back to course

61. Checking Disk Usage (`df` and `du`)

Linux Basics: From Zero to CLI Hero

Monitoring Storage

Understanding how much disk space is used is critical for system health.

1. df (Disk Filesystem)

df reports on the filesystem usage (how much space is used on entire partitions/mounts).

Human Readable Output (-h):

bash $ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 39G 7.5G 30G 20% / tmpfs 1.9G 0 1.9G 0% /run/shm

2. du (Disk Usage)

du reports on the disk space usage of specific files or directories.

Reporting Directory Size:

bash

Show total size of the current directory and its contents in human readable format

$ du -sh . 1.2G .

Listing Sizes of Subdirectories:

bash

Show the size of all immediate subdirectories

$ du -h --max-depth=1 /var 4.0K /var/mail 78M /var/log 4.2G /var/lib 4.3G /var