Last active
December 9, 2015 17:19
-
-
Save dyndna/678142414ea7298c2cd2 to your computer and use it in GitHub Desktop.
disk usage summary per user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 ## |
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
I tend to enable disk quotas instead, leaving them set to 0, only using repquota to quickly report in usage.