Interview Questions/Phone Screen/Find Large Files with Bash
BeginnerPhone
1 min

Find Large Files with Bash

LinuxScriptingTroubleshooting
Advertisement
Interview Question

Which command would you use to find the largest files/directories consuming disk space in a path?

Key Points to Cover
  • `du -sh * | sort -h` to summarize and sort by size
  • `du -ah /path | sort -h | tail` for top offenders
  • Optionally use `ncdu` for interactive exploration
Evaluation Rubric
Provides correct du usage50% weight
Sorts human-readable sizes25% weight
Mentions ncdu or alternatives25% weight
Hints
  • 💡Remember `-x` to stay on one filesystem if needed.
Common Pitfalls to Avoid
  • ⚠️Failing to sort the output (e.g., just `du -sh`), which makes identifying the largest items difficult without manual scanning.
  • ⚠️Omitting the `-h` (human-readable) flag, resulting in raw byte counts that are cumbersome and time-consuming to interpret quickly.
  • ⚠️Not understanding the distinction between `du` (disk usage of specific files/directories) and `df` (filesystem free space for entire partitions).
  • ⚠️Forgetting to use `sudo` or appropriate permissions when necessary, which can lead to incomplete or inaccurate results due to inaccessible directories.
  • ⚠️Only looking at directory sizes (default `du`) and missing individual large files by not using the `-a` option when a comprehensive file-level scan is needed.
Potential Follow-up Questions
  • How to exclude directories?
  • How to check inode usage?
Advertisement