From 7c1767ef8293b148df9d265d9a5470f17a8f8327 Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Tue, 4 Mar 2025 17:15:07 +0000 Subject: [PATCH] added a script to display the amount of space used by a folder, how much space each of the subdirectories is using and how many files are in each --- folder_metrics.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 folder_metrics.sh diff --git a/folder_metrics.sh b/folder_metrics.sh new file mode 100755 index 0000000..33e34c1 --- /dev/null +++ b/folder_metrics.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Check if a directory is provided as an argument +if [ -z "$1" ]; then + echo "Usage: $0 " + 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