Skip to content

Instantly share code, notes, and snippets.

@AndrewWCarson
Created June 16, 2021 09:36
Show Gist options
  • Save AndrewWCarson/a4a802175d94f2be1e04279f296c9975 to your computer and use it in GitHub Desktop.
Save AndrewWCarson/a4a802175d94f2be1e04279f296c9975 to your computer and use it in GitHub Desktop.
Prints all non-system users, their home directory, and the size of the directory in human-readable format.
#!/bin/zsh
for user in $(dscl . list /Users UniqueID | awk '$2 >= 500 {print $1}'); do
userHome=$(dscl . read /Users/"$user" NFSHomeDirectory | sed 's/NFSHomeDirectory://' | grep "/" | sed 's/^[ \t]*//')
if [ -d "$userHome" ]; then
size=$(/usr/bin/du -h -d 0 "$userHome" 2> /dev/null | awk '{print $1}')
echo "$user:$userHome:$size"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment