Skip to content

Instantly share code, notes, and snippets.

@JensForstmann
Created June 17, 2019 14:01
Show Gist options
  • Select an option

  • Save JensForstmann/2e7aab580de5bfb05edb2d724eeefc8a to your computer and use it in GitHub Desktop.

Select an option

Save JensForstmann/2e7aab580de5bfb05edb2d724eeefc8a to your computer and use it in GitHub Desktop.
Get used user quotas from btrfs volume
#!/bin/bash
userList=$(cat /etc/passwd)
volume=/volume1/
usedSpaceList=""
IFS=$'\n'
for user in $userList
do
userName=$(echo $user | cut -d : -f 1)
userId=$(echo $user | cut -d : -f 3)
usedSpace=$(btrfs usrquota show -an -u $userId $volume | cut -d " " -f 3 | awk '{s+=$1} END {printf "%.0f", s}')
usedSpaceHumanReadable=$(echo $usedSpace | numfmt --to=iec)
usedSpaceList=$(echo -e "$usedSpaceList\n$usedSpace\t$usedSpaceHumanReadable\t$userName")
done
echo "$usedSpaceList" | sort -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment