One liner to show CPU, RAM and HDD usage
You can use this
echo "CPU `LC_ALL=C top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1}'`% RAM `free -m | awk '/Mem:/ { printf("%3.1f%%", $3/$2*100) }'` HDD `df -h / | awk '/\// {print $(NF-1)}'`"
The output is
CPU 7.4% RAM 33.9% HDD 94%
For CPU usage (average of (user+system)/(user+system+idle)
times over 0.1 seconds):
(grep 'cpu ' /proc/stat;sleep 0.1;grep 'cpu ' /proc/stat)|awk -v RS="" '{print "CPU "($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)"%"}'
For RAM usage ((total-available)/total
):
awk '/MemTotal/{t=$2}/MemAvailable/{a=$2}END{print 100-100*a/t"%"}' /proc/meminfo
For HDD usage (only of the volume mounted as /
):
df | awk '/ \/$/{print "HDD "$5}'