I have not posted articles lately due to some personal work, but I am back again with a very smart trick that will help you to find the number of processors a Linux machine has. This tip is very useful when you are working on a remote Linux machine and want to grep information about the processors.
Open a new terminal (CTRL+ALT+T) in Ubuntu and run the following command.
You can easily find out the processor by scrolling down and on the right of it you will find a number which is used to show the number of processor on the machine you are using.
Depending on the number of processors your machine has you will encounter the word processor many times. A Linux geek uses piping (pass the output of one command as input for another command) to find out how many times the word processor appears in the file.
Run the following command to find out the number of processors in your machine.
cat /proc/cpuinfo | grep processor | wc -l
We use the cat command to print the file on the standard output and pass it to the grep command as input. Then we tell grep to find the word processor and grep it. But, how many times does this word appear? The wc command is used to count word and it helps us to solve our problem.
I get the following output after running the above command.
$ cat /proc/cpuinfo | grep processor | wc -l 4
The /proc/cpuinfo is a plain text file that contains information about the central processing units on a computer. You can use the cat command to display its content on the terminal and find alot of information by yourself.
Warning: The /proc/cpuinfo is a read-only file so do not try to make any changes to it or you will end up damaging the file and probably your system.