Bird
Raised Fist0
Linux CLIscripting~20 mins

df (disk free space) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Disk Space Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Understanding the output of df -h
What is the output of the command df -h on a typical Linux system?
Linux CLI
df -h
AShows disk usage in human-readable format with sizes like 1K, 234M, 2G
BShows only the total disk size without usage details
CShows network usage statistics
DShows a list of running processes and their disk usage
Attempts:
2 left
💡 Hint
The -h option means human-readable sizes.
💻 Command Output
intermediate
1:30remaining
Output of df --total
What does the df --total command add to the usual df output?
Linux CLI
df --total
AShows only the total size of the root filesystem
BDisplays disk usage for network filesystems only
CAdds a summary line showing total disk usage across all filesystems
DShows disk usage sorted by mount point name
Attempts:
2 left
💡 Hint
Look for a line labeled 'total' at the end.
📝 Syntax
advanced
1:30remaining
Correct usage of df to show inode usage
Which command correctly shows inode usage with df?
Adf -i
Bdf --inodes
Cdf -h -i
Ddf --inode-usage
Attempts:
2 left
💡 Hint
The option for inode info is a short flag.
🔧 Debug
advanced
1:30remaining
Why does df /nonexistent fail?
What error does the command df /nonexistent produce and why?
Linux CLI
df /nonexistent
Adf: Invalid argument - because the path is not a mount point
Bdf: Permission denied - because the user lacks rights
Cdf: Device busy - because the path is in use
Ddf: /nonexistent: No such file or directory - because the path does not exist
Attempts:
2 left
💡 Hint
Check if the path exists before running df.
🚀 Application
expert
2:00remaining
Automate disk usage alert with df
You want to write a script that alerts you if any mounted filesystem is more than 90% full. Which command pipeline correctly extracts the usage percentage and filters filesystems over 90%?
Adf -h | grep -v Filesystem | awk '{if ($5 > 90) print $1, $5}'
Bdf -h | awk 'NR>1 {sub(/%/, "", $5); if ($5 > 90) print $1, $5"%"}'
Cdf | awk '{if ($5 > 90) print $1, $5}'
Ddf -h | awk '{if ($5+0 > 90) print $1, $5}'
Attempts:
2 left
💡 Hint
You need to remove the % sign before comparing numbers.

Practice

(1/5)
1. What does the df command do in Linux?
easy
A. Shows disk free space on mounted filesystems
B. Displays running processes
C. Lists files in a directory
D. Shows network connections

Solution

  1. Step 1: Understand the purpose of df

    The df command is used to report disk space usage on mounted filesystems.
  2. Step 2: Compare with other commands

    Other options like listing processes or files are done by different commands like ps or ls.
  3. Final Answer:

    Shows disk free space on mounted filesystems -> Option A
  4. Quick Check:

    df = disk free space [OK]
Hint: Remember: df = disk free space quick check [OK]
Common Mistakes:
  • Confusing df with ls or ps commands
  • Thinking df shows network info
  • Assuming df lists files
2. Which of these is the correct syntax to show disk space in human-readable format?
easy
A. df -r
B. df -h
C. df --list
D. df -x

Solution

  1. Step 1: Identify the option for human-readable sizes

    The -h option in df shows sizes in easy units like MB, GB.
  2. Step 2: Check other options

    Options like -r, --list, or -x do not provide human-readable output.
  3. Final Answer:

    df -h -> Option B
  4. Quick Check:

    -h means human-readable [OK]
Hint: Use -h for human-readable sizes with df [OK]
Common Mistakes:
  • Using -r or -x instead of -h
  • Forgetting the dash before h
  • Trying --list which is invalid
3. What will be the output of the command df -h /home?
medium
A. Shows disk usage of the /home filesystem in human-readable format
B. Shows disk usage of the root filesystem
C. Shows all mounted filesystems in bytes
D. Shows network disk usage

Solution

  1. Step 1: Understand the command arguments

    The command df -h /home checks disk space for the /home directory only, with human-readable sizes.
  2. 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.
  3. Final Answer:

    Shows disk usage of the /home filesystem in human-readable format -> Option A
  4. Quick Check:

    df -h /home = /home usage human-readable [OK]
Hint: Add path after df -h to check specific folder space [OK]
Common Mistakes:
  • Assuming it shows all filesystems
  • Confusing /home with root filesystem
  • Expecting output in bytes without -h
4. You run df -h /nonexistent and get an error. What is the likely cause?
medium
A. You need root permissions to run df
B. The df command does not support -h option
C. The path /nonexistent does not exist or is not mounted
D. The disk is full

Solution

  1. Step 1: Analyze the error cause

    Running df on a path that does not exist or is not mounted causes an error.
  2. Step 2: Check other options

    df supports -h, does not require root, and disk full does not cause this error.
  3. Final Answer:

    The path /nonexistent does not exist or is not mounted -> Option C
  4. Quick Check:

    Invalid path = error [OK]
Hint: Check if path exists before using df on it [OK]
Common Mistakes:
  • Thinking -h is unsupported
  • Assuming root needed for df
  • Confusing disk full with path error
5. You want to check disk space for all mounted filesystems but exclude the tmpfs type. Which command will do this?
hard
A. df -h --exclude tmpfs
B. df -h --exclude=tmpfs
C. df -h --ignore-type tmpfs
D. df -h -x tmpfs

Solution

  1. Step 1: Identify the correct option to exclude filesystem type

    The -x option excludes a filesystem type in df. So df -h -x tmpfs excludes tmpfs.
  2. Step 2: Verify other options

    Options like --exclude-type, --exclude, or --ignore-type are invalid for df.
  3. Final Answer:

    df -h -x tmpfs -> Option D
  4. Quick Check:

    -x excludes filesystem type [OK]
Hint: Use -x to exclude filesystem types in df [OK]
Common Mistakes:
  • Using invalid options like --exclude-type
  • Confusing exclude with ignore
  • Forgetting dash before x
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard