Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)

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.

1 Answer

0 votes
by (36.8k points)

You can try:

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

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 15, 2019 in AWS by yuvraj (19.1k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...