Why disk management prevents outages in Linux CLI - Performance Analysis
We want to understand how disk management tasks affect system performance over time.
Specifically, how the time to complete disk checks or cleanups grows as disk size or file count increases.
Analyze the time complexity of this disk check script.
#!/bin/bash
files=$(find /mnt/data -type f)
for file in $files; do
if ! file -b "$file" | grep -q "text"; then
echo "$file is not a text file"
fi
done
This script scans all files in a disk directory and reports non-text files to help prevent disk issues.
Look for loops or repeated checks.
- Primary operation: Looping over each file found on the disk.
- How many times: Once for every file in the directory and its subdirectories.
As the number of files grows, the script checks each one individually.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 file checks |
| 100 | About 100 file checks |
| 1000 | About 1000 file checks |
Pattern observation: The time grows directly with the number of files; doubling files doubles work.
Time Complexity: O(n)
This means the script takes longer as more files exist, growing in a straight line with file count.
[X] Wrong: "The script runs in constant time no matter how many files there are."
[OK] Correct: Each file must be checked individually, so more files mean more work and longer time.
Understanding how disk checks scale helps you explain system reliability and maintenance in real jobs.
"What if the script also checked file sizes before running the file type check? How would that affect time complexity?"