Back
How do I get the system CPU usage and give it in percent using bash, for example?
Sample output:
57%
In case there is more than 1 core, it would be nice if your average percentage could be calculated.
You can try:
top -bn1 | grep "Cpu(s)" | \ sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | \ awk '{print 100 - $1"%"}'
top -bn1 | grep "Cpu(s)" | \
sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | \
awk '{print 100 - $1"%"}'
Want to be a Linux expert? Come and join this Linux course
Do check out the video below for better understanding of Linux
31k questions
32.8k answers
501 comments
693 users