Skip to content

Instantly share code, notes, and snippets.

@maciekish
Created September 4, 2023 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maciekish/34ddc11aa41b5f12d5c2c1929122b67e to your computer and use it in GitHub Desktop.
Save maciekish/34ddc11aa41b5f12d5c2c1929122b67e to your computer and use it in GitHub Desktop.
unRAID Folder Stats
#!/bin/bash
# Function to convert bytes to human-readable format
to_human_readable() {
local size=$1
if [ $size -lt 1024 ]; then
echo "${size}B"
elif [ $size -lt $((1024*1024)) ]; then
echo "$((size/1024))KB"
elif [ $size -lt $((1024*1024*1024)) ]; then
echo "$((size/(1024*1024)))MB"
else
echo "$((size/(1024*1024*1024)))GB"
fi
}
# Check if folder is specified
if [ -z "$1" ]; then
echo "Usage: $0 /path/to/folder"
exit 1
fi
# Initialize a temporary file to store results
tempfile=$(mktemp)
# Iterate through all files in the folder
find "$1" -type f -print0 | while IFS= read -r -d '' filepath; do
# Search each disk for the file
for disk in /mnt/disk*; do
if [ -e "${disk}${filepath#*/mnt/user}" ]; then
echo "$(basename $disk)|$filepath|$(stat -c%s "$filepath")" >> $tempfile
break
fi
done
done
# Initialize associative arrays for file count and size
declare -A file_count
declare -A file_size
# Process the temporary file to summarize results
while IFS='|' read -r disk filepath size; do
file_count["$disk"]=$((file_count["$disk"] + 1))
file_size["$disk"]=$((file_size["$disk"] + size))
done < $tempfile
# Remove the temporary file
rm -f $tempfile
# Print summary
echo "Summary:"
for disk in "${!file_count[@]}"; do
echo "Array Disk: $disk"
echo " Number of files: ${file_count[$disk]}"
echo " Total size: $(to_human_readable ${file_size[$disk]})"
done
@maciekish
Copy link
Author

Quick and dirty way to figure out which disks a folder is spread on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment