0
0
Linux CLIscripting~5 mins

df (disk free space) in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes your computer's storage gets full and you need to check how much space is left. The df command shows you the free and used disk space on your drives so you can manage your files better.
When you want to see how much space is left on your hard drive before saving large files.
When your computer warns you about low disk space and you want to find which drive is full.
When you are cleaning up files and want to check if deleting files freed enough space.
When you want to monitor disk usage on a server to avoid running out of space.
When you want to check the size of mounted drives like USB sticks or external disks.
Commands
This command shows disk space usage for all mounted filesystems in blocks. It gives a quick overview of used and available space.
Terminal
df
Expected OutputExpected
Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 20511356 12345678 7156678 64% /
This command shows disk space usage in a human-readable format, using KB, MB, or GB so it's easier to understand.
Terminal
df -h
Expected OutputExpected
Filesystem Size Used Avail Use% Mounted on /dev/sda1 20G 12G 6.8G 64% /
-h - Show sizes in human-readable format (KB, MB, GB)
This command adds the type of filesystem (like ext4 or tmpfs) to the output, helping you know what kind of storage is used.
Terminal
df -T
Expected OutputExpected
Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/sda1 ext4 20511356 12345678 7156678 64% /
-T - Display filesystem type
This command shows disk usage only for the /home directory, useful when you want to check space on a specific folder's drive.
Terminal
df -h /home
Expected OutputExpected
Filesystem Size Used Avail Use% Mounted on /dev/sda2 50G 30G 18G 63% /home
Key Concept

If you remember nothing else from this pattern, remember: df shows how much disk space is used and free on your drives so you can manage storage.

Common Mistakes
Running df without -h and expecting easy-to-read sizes
The output shows sizes in blocks which are hard to understand quickly.
Use df -h to see sizes in KB, MB, or GB for easier reading.
Using df on a directory without knowing it shows the filesystem containing that directory
You might think it shows only that folder's size, but it shows the whole drive's usage.
Understand df reports disk usage per filesystem, not per folder size.
Summary
Use df to check disk space usage on all mounted filesystems.
Add -h flag to see sizes in human-readable format like MB or GB.
Use -T flag to see the type of filesystem for each mount point.
You can specify a directory to see disk usage for its filesystem only.