Bird
Raised Fist0
Linux CLIscripting~10 mins

df (disk free space) in Linux CLI - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - df (disk free space)
Run 'df' command
↓
System reads disk info
↓
Calculate used and available space
↓
Format output in columns
↓
Display output to user
↓
User reads disk space info
The 'df' command runs, system gathers disk usage info, formats it, and shows it to the user.
Execution Sample
Linux CLI
df -h
Shows disk space usage in a human-readable format with sizes like GB and MB.
Execution Table
StepActionCommand OutputExplanation
1Run 'df -h'Filesystem Size Used Avail Use% Mounted onHeader row shows column names
2System reads disk info/dev/sda1 50G 20G 28G 42% /Shows disk device, total size, used, available, usage %, and mount point
3System reads disk infotmpfs 2.0G 0 2.0G 0% /dev/shmShows temporary filesystem with usage info
4System reads disk infodevtmpfs 1.9G 0 1.9G 0% /devAnother virtual filesystem info
5Display output(end of output)All disk info lines displayed
6User reads output(no command output)User sees disk usage summary
7Exit(command ends)Command finishes after showing info
💡 All disk partitions info displayed, command ends normally
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
Filesystem/dev/sda1/dev/sda1, tmpfs/dev/sda1, tmpfs, devtmpfs/dev/sda1, tmpfs, devtmpfs
Size50G50G, 2.0G50G, 2.0G, 1.9G50G, 2.0G, 1.9G
Used20G20G, 020G, 0, 020G, 0, 0
Avail28G28G, 2.0G28G, 2.0G, 1.9G28G, 2.0G, 1.9G
Use%42%42%, 0%42%, 0%, 0%42%, 0%, 0%
Mounted on//, /dev/shm/, /dev/shm, /dev/, /dev/shm, /dev
Key Moments - 3 Insights
Why does 'df' show multiple lines with different filesystems?
Each line shows a different disk or virtual filesystem mounted on your system, as seen in execution_table rows 2-4.
What does the 'Use%' column mean?
It shows the percentage of disk space used on that filesystem, for example 42% in row 2 of execution_table.
Why do some filesystems show 0 used space?
Virtual filesystems like tmpfs and devtmpfs are temporary and often empty, so their used space is 0, as shown in rows 3 and 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the 'Avail' space for /dev/sda1 at step 2?
A20G
B28G
C42%
D50G
💡 Hint
Check the 'Avail' column in row 2 of execution_table.
At which step does the command output the header row?
AStep 5
BStep 2
CStep 1
DStep 7
💡 Hint
Look at execution_table row 1 for the header output.
If the disk was full, how would the 'Use%' column change in the table?
AIt would show 100%
BIt would show 50%
CIt would show 0%
DIt would be empty
💡 Hint
Use% shows how full the disk is, see row 2 for example.
Concept Snapshot
df command shows disk space usage.
Use 'df -h' for human-readable sizes.
Output columns: Filesystem, Size, Used, Avail, Use%, Mounted on.
Each line shows one disk or virtual filesystem.
Useful to check free space quickly.
Full Transcript
The 'df' command in Linux shows how much disk space is used and free on your system. When you run 'df -h', it lists each disk or virtual filesystem with columns for total size, used space, available space, usage percentage, and where it is mounted. The command reads this info from the system, formats it, and displays it. For example, /dev/sda1 might have 50G total, 20G used, and 28G free, which is 42% used. Virtual filesystems like tmpfs often show 0 used space. This helps you quickly see how full your disks are.

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