#! /bin/sh

clear
echo -e "Overal disk space lookup.\n"
echo -e "\nInodes:"
echo "Filesystem      Inodes  IUsed   IFree IUse% Mounted on"
df -i|grep -w /

space_check() {
du -sk $path/* | sort -nr | awk 'BEGIN{ pref[1]="K"; pref[2]="M"; pref[3]="G"; pref[4]="T";} { total = total + $1; x = $1; y = 1; while( x > 1024 ) { x = (x + 1023)/1024; y++; } printf("%g%s\t%s\n",int(x*10)/10,pref[y], $"{2}" ); } END { y = 1; while( total > 1024 ) { total = (total + 1023)/1024; y++; } printf("Total: %g%s\n",int(total*10)/10,pref[y]); }'|head -n15
}

echo -e "\nDistribution:"
path=""
space_check 2> /dev/null

echo -e "\nBiggest files:"
(find / -type f -size +100M -exec du -shx {} \; | sort -rh | head -n5) 2> /dev/null

echo -e "\nLarge logs (+100M):"
(find / -type f -size +100M \( -name "*_log" -o -name "*.log" \) -exec du -shx {} \; | sort -rh |head -n5)  2> /dev/null

echo -e "\nWant additional info?"
read klk
if [[ $klk == "yes" || $klk == "Yes" || $klk == "YES" || $klk == "y" ]]; then
        (while true; do
                echo -e "\nWrite down a full path:\n"
                read path
                space_check 2> /dev/null
                echo -e "\nAnother one?"
                read klk2
                if [[ $klk2 == "no" || $klk2 == "NO" || $klk2 == "n" ]]; then
                echo "Ok, the script will be stopped."
                break
                fi
done
        )
else
        echo -e "\n\nOk, Done."
fi
