Created
January 26, 2011 10:56
-
-
Save zbyhoo/796553 to your computer and use it in GitHub Desktop.
Calculates total file space usage for each user in specified directory and subdirectories.
This file contains hidden or 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 | |
function usage() | |
{ | |
echo "Usage: `basename $0` [dir]" | |
echo " dir - directory to check (default is current directory)" | |
} | |
if [ "$1" == "-h" ] | |
then | |
usage | |
exit 0 | |
fi | |
if [ $# -gt 1 ] | |
then | |
echo "Too many arguments." | |
usage | |
exit 1 | |
elif [ ! -d $1 ] | |
then | |
echo "Directory ($1) not exists." | |
usage | |
exit 1 | |
fi | |
find $1 -type f | xargs ls -l | awk '{print $3 " " $5}' | sort | awk '{prev=current; current=$1; if(prev==current){size=size+$2}else if(user!=""){print user " " size; size=$2;} user=$1} END{print user " " size}' | sort -gr -k2 | awk '{arr[0]=""; arr[1]="K"; arr[2]="M"; arr[3]="G"; arr[4]="T"; var=$2; iter=0; while(var>1024){var/=1024; iter++;}; printf("%-15s %.2f%s\n", $1, var, arr[iter])}' | awk '{comm=sprintf("finger %s | grep Name | sed '\''s/.*Name: //g'\'' | tr -d '\''\\n'\'' ", $1); while(comm | getline name){}; printf("%-15s %-25s %-10s\n", $1, name, $2); }' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment