Resource Utilization in Unix

Disk space

Simple:

df -h

More information:

read -rp "Enter directory: " location; clear; hostname; date; df -h "$location"; echo; df -i "$location"; echo; echo "Largest Directories:"; du -hcx --max-depth=2 "$location" 2> /dev/null | grep [0-9]G | sort -grk 1 | head -n 15 | cut -c -78 ; echo "Largest Files:"; nice -n 19 find "$location" -mount -type f -print0 2> /dev/null| xargs -0 du -hk | sort -rnk1| head -n 20 | awk '{printf "%12.2f GB\t%s\n",($1/1024/1024),$NF}' | grep -Ev "0\.00 GB" | cut -c -77  

Find biggest files under current directory:

nice -n 19 find . -mount -type f -print0 2> /dev/null| xargs -0 du -hk | sort -rnk1| head -n 20 | awk '{printf "%12.2f MB\t%s\n",($1/1024),$NF}' | grep -Ev "0\.00 MB" | cut -c -77  

Find biggest files under current directory - Modified in the last 60 min:

nice -n 19 find . -cmin -60 -mount -type f -xdev -print0 2> /dev/null| xargs -0 du -hk | sort -rnk1| head -n 20 | awk '{printf "%12.2f GB\t%s\n",($1/1024/1024),$NF}' | grep -Ev "0\.00 GB" | cut -c -77  

Find biggest directories under current directory:

du -hcx --max-depth=2 . 2> /dev/null | grep [0-9]G | sort -grk 1 | head -n 15 | cut -c -78 ;  

Also identify disk writes:

atop -D  

Memory:

atop -m

CPU

atop -C

For those times that your system is bogged down by god knows what:

process=( R S D K T Z X );  
state=( "(running)" "(sleeping)" "(sleeping)" "(sleeping)" "(stopped)" "(zombie)" "(zombie)" )  
process_name=(TASK_RUNNING TASK_INTERRUPTIBLE TASK_UNINTERRUPTIBLE TASK_KILLABLE TASK_STOPPED/TRACED EXIT_ZOMBIE EDIT_DEAD );  
counter=0;  
for i in "${process[@]}";  
do  
    [[ "$counter" == "0" ]] && w | head -n 1;
    printf "%s\t%d\t%s\t%s\n" "$i" "$(ps -e v | grep "$i" -c)" "${state[$counter]}" "${process_name[$counter]}";
    ((counter++))
done;  

Check last file for first instance recurrence in the first field (Great for helping to identify problem IPs):

awk '{print $1}' $_ | sort | uniq -c | sort -n | tail -30