commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
Show the current load of the CPU as a percentage.
Read the load from /proc/loadavg and convert it using sed:
Strip everything after the first whitespace:
sed -e 's/ .*//'
Delete the decimal point:
sed -e 's/\.//'
Remove leading zeroes:
sed -e 's/^0*//'
There are 2 alternatives - vote for the best!
This version is precise and requires one second to collect statistics. Check sample output for a more generic version and also a remote computer invocation variant. It doesn't work with the busybox version of the 'top' command but can be adjusted
If you can do better, submit your command here.
You must be signed in to comment.