Skip to content

Instantly share code, notes, and snippets.

@filipnet
Created February 13, 2025 07:11
Show Gist options
  • Select an option

  • Save filipnet/beed6db0289cd3532de2981ae4516c8d to your computer and use it in GitHub Desktop.

Select an option

Save filipnet/beed6db0289cd3532de2981ae4516c8d to your computer and use it in GitHub Desktop.
This script extracts all home directories from /etc/passwd, regardless of their location. It then checks if each home directory contains a Maildir folder. If a Maildir exists, the script displays the total size of the home directory along with the size of the Maildir and its subdirectories.
#!/bin/bash
# Get all home directories from /etc/passwd
HOMEDIRS=$(awk -F: '$6 !~ /^$/ {print $6}' /etc/passwd | sort -u)
# Loop through each home directory
for dir in $HOMEDIRS; do
MAILDIR="$dir/Maildir"
# Check if the Maildir exists
if [ -d "$MAILDIR" ]; then
echo "=== $dir ==="
du -h --max-depth=2 "$dir" | grep -E "^|/Maildir"
echo ""
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment