A simple Bash utility that audits a target directory for large or sensitive files, logs the findings, and creates a timestamped archive. Designed for quick system hygiene checks or small-scale backup tasks.
-
Audit files
- Logs the top 5 largest files in the directory.
- Searches for large, log, or key files (excludes any matching
DEBUGto avoid noisy debug logs).
-
Archiving
- Creates a compressed
.tar.gzarchive of the target folder. - Automatically timestamps the archive name.
- Excludes
.binfiles from the backup.
- Creates a compressed
-
System summary
- Records disk usage of the target folder.
- Captures overall disk space available on the system.
-
Status feedback
- Color-coded output for easy readability.
- Clear success/failure messages for each step.
-
Note
Archiving Behavior
By default, the script preserves the full path of the target directory inside the archive:
tar --exclude='*.bin' -czf "archive/$(basename "$target_dir")-$timestamp.tar.gz" "$target_dir" Optional: Archive Without Full Path
If you prefer to store only the folder name and its contents (without full system paths),
you can comment out the default line and use this alternative:
tar --exclude='*.bin' -czf "archive/$(basename "$target_dir")-$timestamp.tar.gz"
-C "$(dirname "$target_dir")" "$(basename "$target_dir")"
Usage ./audit_backup.sh target_directory
Example: ./audit_backup.sh /var/www
Output All results are saved under the logs/ and archive/ directories:
logs/largest_files.txt → Top 5 largest files
logs/findings.txt → Sensitive or large files (with DEBUG excluded)
logs/summary.txt → Disk usage summary
archive/target-YYYY-MM-DD-HHMM.tar.gz → Timestamped archive
Example Run [INFO] Scanning folder: /var/www [INFO] Logging top 5 largest files... [SUCCESS] Top 5 largest files saved to logs/largest_files.txt [INFO] Searching for large, log, or key files (excluding DEBUG)... [SUCCESS] Filtered file results saved to logs/findings.txt [INFO] Creating archive (excluding .bin)... [DONE] Archive created: archive/www-2025-08-19-2230.tar.gz [SUCCESS] Summary saved to logs/summary.txt All tasks completed successfully. Requirements Linux / Unix environment
bash, tar, du, df, grep, find
Notes Intended for test and learning environments.
Not optimized for production-scale backup.
Use with caution on sensitive directories.
Script auto-creates logs/ and archive/ if missing.
Tested on Ubuntu (bash 5+). Should work on most Linux distributions.
For demonstration purposes, the repository includes a scan_targets/ folder used to test the script. It contains sample files to illustrate how audit_backup.sh works:
debug.log→ Simulated debug log fileerror.log→ Simulated error log filesecret.key→ Dummy key filejunkfile.bin→ 5MB random file generated with:head -c 5M /dev/urandom > junkfile.bin