Create a small Bash utility named audit.sh that analyzes a target directory and outputs a structured audit report. The task focuses on practicing project organization, basic file system traversal, and basic Bash scripting.
Steps:
Create audit.sh in this repository. It should accept an optional argument TARGET_DIR. If omitted, use the current directory.
The script should scan TARGET_DIR recursively and compute:
Total number of files (regular files)
Cumulative size of all regular files in bytes
Number of hidden files or directories (names starting with a dot), excluding the special entries . and ..
Number of symbolic links and how many of them are broken (dangling)
The top 5 largest regular files (path and size)
The script should print a human-friendly summary to stdout and also write a machine-readable report to audit_report.txt in the same directory. The report can be a simple key:value format or a concise JSON-like block; be consistent.
Example usage: bash audit.sh /path/to/dir
Deliverables:
audit.sh script in the repository
audit_report.txt produced by running the script on this repository (the current directory) or on an example directory you provide.
Notes:
Stay robust against spaces in filenames. Use safe quoting and find/awk/sort where needed.
The script should exit with non-zero status if TARGET_DIR does not exist.
Bonus:
Include a --summary-only flag that prints only the high-level counts.