Created
January 30, 2013 12:40
-
-
Save pjbriggs/4673026 to your computer and use it in GitHub Desktop.
Report disk usage under specified directory (largest subdirectories and largest files)
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/sh | |
# | |
# Report disk usage | |
# | |
# Usage: usage.sh DIR | |
# | |
if [ $# -eq 0 ] ; then | |
echo "Usage: $0 DIR" | |
exit | |
fi | |
# | |
DATA_DIR=$1 | |
DIR_SIZE_LIMIT=4000000 | |
FILE_SIZE_LIMIT=1000000 | |
echo "======================================" | |
echo Top level usage in $DATA_DIR | |
echo "--------------------------------------" | |
du -sh $DATA_DIR/* | sort -hr | |
echo "--------------------------------------" | |
du -sh $DATA_DIR | sort -hr | |
# | |
disk_usage=`du -ka $DATA_DIR | sort -nr` | |
# | |
echo "======================================" | |
echo Directories larger than $DIR_SIZE_LIMIT K | |
echo "--------------------------------------" | |
IFS=$'\n' | |
for line in $disk_usage ; do | |
d=`echo $line | cut -f2` | |
s=`echo $line | cut -f1` | |
if [ -d $d ] ; then | |
if [ $s -gt $DIR_SIZE_LIMIT ] ; then | |
ls_out=`ls -lhd $f` | |
owner=`echo $ls_out | cut -f3 -d" "` | |
size=`du -sh $d | cut -f1` | |
echo $size$'\t'$owner$'\t'$d | |
else | |
break | |
fi | |
fi | |
done | |
# | |
echo "======================================" | |
echo Files larger than $FILE_SIZE_LIMIT K | |
echo "--------------------------------------" | |
IFS=$'\n' | |
for line in $disk_usage ; do | |
f=`echo $line | cut -f2` | |
s=`echo $line | cut -f1` | |
if [ ! -d $f ] ; then | |
if [ $s -gt $FILE_SIZE_LIMIT ] ; then | |
#echo $line | |
ls_out=`ls -lh $f` | |
owner=`echo $ls_out | cut -f3 -d" "` | |
size=`du -sh $f | cut -f1` | |
echo $size$'\t'$owner$'\t'$f | |
else | |
break | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment