Files
shell/folder_metrics.sh

28 lines
614 B
Bash
Executable File

#!/bin/bash
# Check if a directory is provided as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <directory>"
exit 1
fi
# Calculate the disk usage of the directory and its children
echo "Disk usage for directory: $1"
echo "---------------------------------"
du -sh "$1"
echo ""
echo "Subdirectories and their usage:"
echo "---------------------------------"
du -sh "$1"/*
echo ""
echo "Number of files in each subdirectory:"
echo "---------------------------------"
for dir in "$1"/*; do
if [ -d "$dir" ]; then
file_count=$(find "$dir" -type f | wc -l)
echo "$dir: $file_count files"
fi
done