Let's see how to get information about the system hardware and see what's inside your computer using 1
the command line. 2
There are many reasons you might need to find out details about your computer hardware. 3
For example, you want to upgrade your system hardware or want to find out why some applications do 4
not run as smoothly as we expect. In virtual environments 5
the information displayed by these commands reflect the configuration of the guest operating system, 6
which is typically different from the physical host system. 7
So for these examples, I'm going to connect to a remote physical machine 8
that runs Linux as the main OS using ssh: ssh-p the port on which the ssh 9
daemon is listening, the username@ and the IP address of the ssh daemon. 10
OK, I'm in and I'm temporarily becoming root in 11
the terminal as these commands must be run as root. 12
And let's take a look at the first command, which displays an overview of the system's harder. I'm 13
running lshw 14
This is a small tool to extract detailed information on the hardware configuration of the machine. 15
It can report the exact memory configuration, the firmware version, mainboard configuration, C.P.U 16
version and speed, case configuration, bus speed and many more; it displays a lot of output 17
so it's recommended to pipe it to less or redirect the output to a file. 18
If you need the output in another format, like say, json or html just pass the -json 19
or -html options 20
So -json and the output will be in json format. 21
Json is a data exchange format used to exchange data between different applications and programming 22
languages. 23
And the htm version. 24
lshw -html 25
And I am redirecting the output to a file, let' say, hw.html 26
OK, this is the output file. 27
html code. You can simply open the file using the browser. 28
Very nice! 29
Or if you are interested only in a summary of the hardware information on the system, pass the -short 30
option. 31
Another command which displays information about all harder elements is inxi and I run it using the 32
-Fx options. 33
Note that this command is not available on all Linux distributions. 34
Another useful command is lscpu 35
It displays information about the central processor unit and the architecture. To get the same information 36
but in another format run lshw -C cpu 37
To filter the output and view only the information you are interested in piped to grep; for example, 38
to view the CPU's speed in megahertz run lscpu 39
| grep -i 40
mhz 41
To display the output in JSON format run lscpu with the -J option. 42
This is Json format. Let's go ahead and see how to get all possible details about the computer's memory. 43
To list all memory modules and their capacity around the dmidecode command. 44
And I'll pass the -T memory option to get only information about the memory. 45
And if you want to see only the memory size pipe the output to grab and search for size | grep 46
-i , I'm searching i sensitive, size 47
There are two memory modules of this size. Or for the maximum memory you can install on the system, 48
search for max. 49
So the maximum capacity is 16 gigabytes. 50
Keep in mind that dmidecode lists information about the ram memory installed on the system. It's 51
not displaying information about the amount of free or used memory of the running system, but you 52
can always run top or free -m to see the amount of memory used or free. 53
To list all the pci buses and details about the devices connected to them like the vga adapter, the graphic 54
card, network adapter, usb ports, sata controllers and so on run the 55
lspci command. 56
Of course, you can always filter the output using grep. For example, I want to see information only 57
about the wireless card so | grep -i wireless 58
| grep -i vga To list the USB controllers and details about the devices connected to them, 59
run the lsusb command. For example, this Logitech is in fact and usb mouse, which is attached. 60
And you can add the -V option, which comes from verbose, to print out detailed information about 61
each USB port. 62
There is a lot of information. 63
Let's move on and see how to get information about the hard disks. 64
You can run the same lshw command we've seen before with the -C and disk option like 65
this. 66
Or to get a single line displaying each disk run lshw -short -C disk 67
Or you can run lsblk to display information about all block devices including the hard disks 68
and partitions. To get more information, including size, filesystem type, the number of sectors 69
and so on run fdisk -l 70
Or run fdisk -l and the name of the disk. 71
For example, /dev/sda and it's displaying information only about this disk drive. With the help of fdisk 72
command, you can view, create, resize, delete, change, copy and move partitions on a hard drive using its 73
own user friendly, text based menu. 74
Another very useful comment is hdparm. 75
This is used to get or set SATA drive parameters; for example, to get details about the specific 76
SATA drive run hdparm with the -i option and the drive as argument: 77
/dev/sda 78
This is the first hard disk drive and this is the second one. 79
To request identification information directly from the drive, with more details, use -I 80
instead of i. So I'm using the -I option. 81
Hdparm can also be used to benchmark or check the performance of hard disks in Linux; for example, 82
on this machine 83
there are two hard disks: 84
sda and sdb. SDda is an SS drive, and this larger one is a classical SATA3 drive. 85
Let's test their performance and see the differences. 86
Let's do a timing test and see the disk read speed. 87
So hdparm -t --directand the name of the disk file /dev/sda 88
I'm hitting enter and waiting for the command to be done. 89
These are the results for the first disc, the ssd1, and let's see the output for the second one. 90
For sdb! 91
By the way, --direct will bypass the page cache, causing the reads to go directly from 92
the drive into the hdparm command buffers. It's a so-called raw input output . And -t means performs 93
timing of device reads for benchmarking and comparison purposes. 94
And we notice that the ssd drive is much faster than the sata one; it is almost four times faster. 95
OK, let's go on! To show information about the wireless devices run iw list 96
There's a lot of output, so it's a good idea to pipe it to less. 97
Most of the commands we've seen so far get the information from the files inside/proc which is a virtual 98
file system. You can always display the contents of those files to get specific information about the 99
hardware components. 100
For example, cat /proc/cpuinfo will display information about the cpu, or cat /proc/meminfo will d 101
display information about the memory. There's also cat/proc/partitions to see the disk partitions or cat/ 102
proc /versions to see the version of the running kernel. 103
By the way, there's also the uname command that's displaying the version of the running kernel. 104
uname -r this is the running kernel's version. 105
You can also run uname -a to see more information. 106
Finally, I'll show you a command that shows battery status and other information. 107
This is useful if you are connected with ssh to a remote laptop and want to check if it works on 108
battery or is connected to the AC power source. 109
This tool is not included in Ubuntu, so I'm installing it: apt install acpi 110
OK, on my machine, it was already installed. And to see the battery status, I'm running acpi- bi 111
So my battery is full and this is its design capacity. 112
If you want to see everything the command can show run it with the -l V: 113
acpi -V 114
That's all! 115
Thank you!