Skip to content

Instantly share code, notes, and snippets.

@dyndna
Last active December 9, 2015 17:19
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 dyndna/678142414ea7298c2cd2 to your computer and use it in GitHub Desktop.
Save dyndna/678142414ea7298c2cd2 to your computer and use it in GitHub Desktop.
disk usage summary per user
#!/bin/bash
# Find disk usage per base directory, per user
# http://unix.stackexchange.com/a/77509/28675
# http://stackoverflow.com/a/32533111/1243763
BASEDIR="$1"
MYTIME="$(date +%d%b%y_%H%M%S%Z)"
if [ -z "$BASEDIR" ] || [ ! -d "$BASEDIR" ]; then
echo -e "Missing or incorrect argument. Specified directory "$1" is not present relative to current working directory, $(pwd)"
exit 1
else
echo -e "\n##### DISK USAGE REPORT - "$MYTIME" ####\n"
find "$BASEDIR" -type f -printf '%u %k\n' | awk '{
arr[$1] += $2
} END {
for ( i in arr ) {
print i": "arr[i]"K"
}
}'
fi
## How to ##
# name this script as diskstats.sh and keep it in ~/bin/diskstats.sh
### for a specific directory, use following ###
# diskstats.sh <dir_path>
# diskstats.sh /verhaak-data/users6
### to recurse over level directories ###
# e.g., users1 to users10 disks under /verhaak-data
# cd /verhaak-data && find . -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 -L1 sh -c 'echo -e "\n#### DISK REPORT for "$0" ####\n" && ~/bin/diskstats.sh "$0"' 2>&1 | tee -a ~/verhaak-data_usage_$(whoami).log
# If you need usage report per level 1 directories within each of 10 verhaak-disks, then issue same command as follows:
# cd /verhaak-data && find . -mindepth 2 -maxdepth 2 -type d -print0 | xargs -0 -L1 sh -c 'echo -e "\n#### DISK REPORT for "$0" ####\n" && ~/bin/diskstats.sh "$0"' 2>&1 | tee -a ~/verhaak-data_usage_$(whoami).log
## END ##
@Natureshadow
Copy link

I tend to enable disk quotas instead, leaving them set to 0, only using repquota to quickly report in usage.

@dyndna
Copy link
Author

dyndna commented Dec 9, 2015

That's very useful and I should ask my server admin to enable disk quota. Thanks!

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