What if you could instantly know exactly how much space is left on your computer without clicking around?
Why df (disk free space) in Linux CLI? - Purpose & Use Cases
Imagine you are managing a computer with many files and programs. You want to know how much space is left on your hard drive before saving more data.
Without a quick tool, you might open folders one by one, checking properties to guess free space.
This manual checking is slow and confusing. You can easily miss some drives or partitions. It's hard to get a clear picture of total free space quickly.
Also, mistakes happen if you guess or forget to check some areas, risking running out of space unexpectedly.
The df command shows all disk space usage and free space in one simple list. It quickly tells you where space is low and where you have plenty.
This saves time and avoids errors by giving a clear, accurate snapshot of your storage.
Right-click folder > Properties > Wait > Note free space > Repeat for each drivedf -h
With df, you can instantly see disk space status, helping you manage storage smartly and avoid surprises.
A system admin uses df to check server disk space before installing new software, preventing crashes from full disks.
Manual checking of disk space is slow and error-prone.
df gives a fast, clear overview of disk usage and free space.
This helps manage storage efficiently and avoid running out of space.
Practice
df command do in Linux?Solution
Step 1: Understand the purpose of
Thedfdfcommand is used to report disk space usage on mounted filesystems.Step 2: Compare with other commands
Other options like listing processes or files are done by different commands likepsorls.Final Answer:
Shows disk free space on mounted filesystems -> Option AQuick Check:
df= disk free space [OK]
- Confusing df with ls or ps commands
- Thinking df shows network info
- Assuming df lists files
Solution
Step 1: Identify the option for human-readable sizes
The-hoption indfshows sizes in easy units like MB, GB.Step 2: Check other options
Options like-r,--list, or-xdo not provide human-readable output.Final Answer:
df -h -> Option BQuick Check:
-hmeans human-readable [OK]
- Using -r or -x instead of -h
- Forgetting the dash before h
- Trying --list which is invalid
df -h /home?Solution
Step 1: Understand the command arguments
The commanddf -h /homechecks disk space for the /home directory only, with human-readable sizes.Step 2: Eliminate other options
It does not show root filesystem unless /home is on root, nor does it show all filesystems or network usage.Final Answer:
Shows disk usage of the /home filesystem in human-readable format -> Option AQuick Check:
df -h /home= /home usage human-readable [OK]
- Assuming it shows all filesystems
- Confusing /home with root filesystem
- Expecting output in bytes without -h
df -h /nonexistent and get an error. What is the likely cause?Solution
Step 1: Analyze the error cause
Runningdfon a path that does not exist or is not mounted causes an error.Step 2: Check other options
dfsupports-h, does not require root, and disk full does not cause this error.Final Answer:
The path /nonexistent does not exist or is not mounted -> Option CQuick Check:
Invalid path = error [OK]
- Thinking -h is unsupported
- Assuming root needed for df
- Confusing disk full with path error
tmpfs type. Which command will do this?Solution
Step 1: Identify the correct option to exclude filesystem type
The-xoption excludes a filesystem type indf. Sodf -h -x tmpfsexcludes tmpfs.Step 2: Verify other options
Options like--exclude-type,--exclude, or--ignore-typeare invalid fordf.Final Answer:
df -h -x tmpfs -> Option DQuick Check:
-xexcludes filesystem type [OK]
- Using invalid options like --exclude-type
- Confusing exclude with ignore
- Forgetting dash before x
Ready to prove it?
Pass the test and this pattern moves unknown
