0
0
Linux CLIscripting~5 mins

df (disk free space) in Linux CLI - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: df (disk free space)
O(n)
Understanding Time Complexity

We want to understand how the time taken by the df command changes as the number of mounted file systems grows.

How does the command's work increase when there are more disks or partitions?

Scenario Under Consideration

Analyze the time complexity of this df command usage.

df -h

This command lists disk space usage for all mounted file systems in a human-readable format.

Identify Repeating Operations

The command internally processes each mounted file system one by one.

  • Primary operation: Reading and calculating disk usage for each mounted file system.
  • How many times: Once per mounted file system.
How Execution Grows With Input

As the number of mounted file systems increases, the command does more work linearly.

Input Size (number of file systems)Approx. Operations
10About 10 disk usage checks
100About 100 disk usage checks
1000About 1000 disk usage checks

Pattern observation: The work grows directly in proportion to the number of file systems.

Final Time Complexity

Time Complexity: O(n)

This means the time taken grows in a straight line as the number of mounted file systems increases.

Common Mistake

[X] Wrong: "The df command always runs instantly no matter how many disks there are."

[OK] Correct: The command must check each file system, so more disks mean more work and longer time.

Interview Connect

Understanding how commands scale with input size helps you reason about system performance and scripting efficiency in real tasks.

Self-Check

"What if the command was run with a specific file system path instead of all? How would the time complexity change?"