Skip to content
Advertisement

CPU and HDD information

I searched but I found nothing for my problem. I would like to have in Linux command line the information about the CPU usage and the local HDDs with formatting text like exactly as the examples below for my program. These examples are command line outputs on MS-Windows. I hope it is possible on Linux, too.

Thank you

JavaScript

Advertisement

Answer

There is no command that gives you a load percentage of the cpu. It’s actually impossible to get that with a system call (nor in linux neither in Windows). What you can get is the number of ticks currently executed (for each field, user, system, io,irq idle)…, then call it again a certain amount of time later and calculate it. That way is how work all the commands for reading the cpu percentage.

Here a script bash that gives you that: (just create a file named for example cpu.sh paste this code and execute to see the results)

JavaScript

For the free space You could use something like this:

JavaScript

wich will give you this output:

JavaScript

sda represents the first disk, sda1 the first partition, sda2, the second one etc. you can add (or change) $6 inside the print to get the mount points instead of the partitions, change the order or even more things.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement