56 lines
1.6 KiB
Bash
56 lines
1.6 KiB
Bash
#!/usr/bin/env bash
|
|
# -----------------------------------------------------------------------------
|
|
# Title: audit-dir-content.sh
|
|
# Purpose: Comprehensive inventory of file types and subdirectory sizes
|
|
# Version: 1.0.0
|
|
# Developer: h@x
|
|
# -----------------------------------------------------------------------------
|
|
|
|
set -euo pipefail
|
|
IFS=$'\n\t'
|
|
|
|
WORKDIR="${PWD##*/}"
|
|
echo "=== typecheck - Check your folders for filetypes v1.1 ==="
|
|
echo
|
|
echo "=== Inventory for: ${WORKDIR} ==="
|
|
echo
|
|
|
|
## 1) FILE-TYPE COUNTS
|
|
echo ">> File-type breakdown (MIME) with counts"
|
|
# Gather MIME types for all regular files at depth=1
|
|
mapfile -t mime_types < <(
|
|
find . -maxdepth 1 -type f -exec file --mime-type --brief {} + 2>/dev/null
|
|
)
|
|
|
|
if [ "${#mime_types[@]}" -eq 0 ]; then
|
|
echo " No regular files detected."
|
|
else
|
|
printf '%s\n' "${mime_types[@]}" \
|
|
| sort \
|
|
| uniq -c \
|
|
| awk '{ printf " %-5s %s\n", $1, $2 }'
|
|
echo
|
|
printf " Total files: %d\n" "${#mime_types[@]}"
|
|
fi
|
|
|
|
echo
|
|
## 2) SUBDIRECTORY SIZES
|
|
echo ">> Subdirectory inventory with sizes"
|
|
# Identify each directory (excluding the current “.”) at depth=1
|
|
mapfile -t subdirs < <(find . -maxdepth 1 -mindepth 1 -type d | sort)
|
|
|
|
if [ "${#subdirs[@]}" -eq 0 ]; then
|
|
echo " No subdirectories present."
|
|
else
|
|
# Compute human-readable size for each
|
|
for dir in "${subdirs[@]}"; do
|
|
# du -sh prints: “<size> <path>”
|
|
size=$(du -sh -- "${dir}" 2>/dev/null | awk '{print $1}')
|
|
name="${dir#./}"
|
|
printf " %-10s %s\n" "${size}" "${name}"
|
|
done
|
|
echo
|
|
printf " Total subdirectories: %d\n" "${#subdirs[@]}"
|
|
fi
|
|
|
|
echo "=== End of report ==="
|