Skip to content

Instantly share code, notes, and snippets.

@egulhan
Created June 11, 2014 14:07
Show Gist options
  • Save egulhan/e39a3cee1ec0420f1c77 to your computer and use it in GitHub Desktop.
Save egulhan/e39a3cee1ec0420f1c77 to your computer and use it in GitHub Desktop.
How to get CPU usage in percent on Linux
top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}'
@samirfor
Copy link

space between % and id cant or not exists:

top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%*\ \{0,1\}id.*/\1/" | awk '{print 100 - $1"%"}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment