Site icon Edumotivation

Most Useful Commands to check System and Hardware Information in Linux

Commands to check System and Hardware Information in Linux

Introduction

A key skill that you need to have as a Linux System Administrator is knowing how to view information about the currently installed Hardware in your system.

And in this lesson, we’re going to look at various tools that you can use to do this.

1. Exploring /proc File System

Now believe it or not one of the best tools for looking at hardware information is the good old /proc directory.

Now we’ve talked about /proc before.

Remember the /proc directory doesn’t really exist in the file system, instead it’s a pseudo file system that dynamically created whenever you access it.

Now as you can see here the /proc directory contains a whole bunch of subdirectories and each one of these subdirectories that you see here in blue represents a process that’s currently running on your system.

If you want to view information about a particular process you could go into the appropriate directory here and there, you’ll find information about that running process.

# ls /proc/
985        driver       loadavg       slabinfo	    1     11     1345  154    1646   17508  1831  2     2174  2336  2428  2492  2675  464   617
986        execdomains  locks         softirqs      10    1100   1355  155    165    1751   1839  20    2182  2337  2430  25    2681  465   648
987        fb           mdstat        stat          1004  1160   1360  156    16599  1753   1849  2000  2195  2341  2432  2525  27    470   8  
990        filesystems  meminfo       swaps         1006  1161   1365  157    166    17550  19    2004  22    2344  2440  2532  2741  483   836
991        fs           misc          sys           1009  1169   1371  158    167    17551  1930  2008  2201  2349  2442  2549  2748  484   9  
acpi       interrupts   modules       sysrq-trigger 1014  1184   1423  1585   168    17569  1934  2013  2205  2352  2450  2551  28    509   920
asound     iomem        mounts        sysvipc       1015  1188   146   1586   169    176    1937  2019  2210  2363  2452  2570  29    510   921
buddyinfo  ioports      mpt           thread-self   1018  1191   1466  159    17     17609  1941  2021  2216  2368  2453  2572  3     511   946
bus        irq          mtrr          timer_list    1019  1197   147   16     170    177    1949  2031  2225  2371  2456  2598  30    512   948
cgroups    kallsyms     net           tty           1022  12     148   160    17039  178    1953  2040  2275  2385  2457  26    4     513   950
cmdline    kcore        pagetypeinfo  uptime        1038  12766  149   161    171    179    1974  2044  2295  2389  2469  2602  450   514   962
consoles   keys         partitions    version       1043  12785  15    1612   172    18     1981  2048  23    2393  2470  2605  451   515   963
cpuinfo    key-users    pressure      vmallocinfo   1046  12938  150   162    17285  180    1985  2051  2303  2397  2474  2606  454   516   978
crypto     kmsg         sched_debug   vmstat        1048  12939  151   1626   173    181    1989  2073  2320  24    2475  2609  455   517   979
devices    kpagecgroup  schedstat     zoneinfo      1068  12951  1518  16291  17341  182    1991  2092  2323  2409  2476  2613  457   53    982
diskstats  kpagecount   scsi                        1070  12952  152   163    174    1827   1992  21    2328  2410  2482  2625  462   6     983
dma        kpageflags   self                        1077  13     153   164    175    183    1996  2166  2331  2426  2489  2653  463   6131  984

But that’s not what we’re concerned about in this lesson.

What we are concerned about are the other files over here within this directory these files contain information about the hardware in your system.

1.1 /proc/cpuinfo explained

For example, the /proc/cpuinfo file contains details about the CPU that’s installed in the system.

And because this is just a text file you can use the cat, less, more or any other text editor you want to view the contents of this file.

Suggested Read: cat Command Examples in Linux

In this example, I use the cat command to view the cpuinfo file on this particular system and when we do I learn that I have an Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz and right here it tells me that it’s a 1 core processor.

I can also see how much cache memory is available on this cpu, there’s more information displayed in the cpuinfo file that we can show on the screen at one time.

# cat /proc/cpuinfo 
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 78
model name	: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz
stepping	: 3
microcode	: 0xcc
cpu MHz		: 2495.999
cache size	: 3072 KB
physical id	: 0
siblings	: 1
core id		: 0
cpu cores	: 1
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 22
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves arat md_clear flush_l1d arch_capabilities
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips	: 4991.99
clflush size	: 64
cache_alignment	: 64
address sizes	: 45 bits physical, 48 bits virtual
power management:

1.2 /proc/devices

In addition, there’s another file in here called /proc/devices.

The devices file contains a list of all the hardware devices installed in the system.

# cat /proc/devices 
Character devices:
  1 mem
  4 /dev/vc/0
  4 tty
  4 ttyS
  5 /dev/tty
  5 /dev/console
  5 /dev/ptmx
  7 vcs
 10 misc
 13 input
 14 sound
 21 sg
 29 fb
116 alsa
128 ptm
136 pts
162 raw
180 usb
188 ttyUSB
189 usb_device
202 cpu/msr
203 cpu/cpuid
216 rfcomm
226 drm
243 aux
244 hidraw
245 usbmon
246 bsg
247 watchdog
248 ptp
249 pps
250 cec
251 rtc
252 dax
253 tpm
254 gpiochip

Block devices:
  8 sd
  9 md
 11 sr
 65 sd
 66 sd
 67 sd
 68 sd
 69 sd
 70 sd
 71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
253 device-mapper
254 mdp
259 blkext

1.3 /proc/dma

There’s another file here called /proc/dma, this contains a list of all the dma channel assignments in the system.

# cat /proc/dma 
 4: cascade

1.4 /proc/interrupts

Another interesting file is the /proc/interrupts file, the contents of a sample interrupts file is shown here.

As you can see it contains a list of IRQ assignments in the system.

For example, we can see that our two ATA controllers on the system are assigned to interrupts 14 and 15, Our Network port is assigned to use interrupt 19, Our USB ports are assigned to use interrupt 17 and 18.

# cat interrupts 
            CPU0       
   0:         90   IO-APIC    2-edge      timer
   1:      13352   IO-APIC    1-edge      i8042
   8:          1   IO-APIC    8-edge      rtc0
   9:          0   IO-APIC    9-fasteoi   acpi
  12:     191742   IO-APIC   12-edge      i8042
  14:          0   IO-APIC   14-edge      ata_piix
  15:      56679   IO-APIC   15-edge      ata_piix
  16:      79971   IO-APIC   16-fasteoi   vmwgfx, snd_ens1371
  17:     375078   IO-APIC   17-fasteoi   ehci_hcd:usb1, ioc0
  18:        976   IO-APIC   18-fasteoi   uhci_hcd:usb2
  19:     223499   IO-APIC   19-fasteoi   ens33
  24:          0   PCI-MSI 344064-edge      PCIe PME, pciehp
  25:          0   PCI-MSI 346112-edge      PCIe PME, pciehp
  26:          0   PCI-MSI 348160-edge      PCIe PME, pciehp
  27:          0   PCI-MSI 350208-edge      PCIe PME, pciehp
  28:          0   PCI-MSI 352256-edge      PCIe PME, pciehp
  29:          0   PCI-MSI 354304-edge      PCIe PME, pciehp
  30:          0   PCI-MSI 356352-edge      PCIe PME, pciehp
  31:          0   PCI-MSI 358400-edge      PCIe PME, pciehp
  32:          0   PCI-MSI 360448-edge      PCIe PME, pciehp
  33:          0   PCI-MSI 362496-edge      PCIe PME, pciehp
  34:          0   PCI-MSI 364544-edge      PCIe PME, pciehp
  35:          0   PCI-MSI 366592-edge      PCIe PME, pciehp
  36:          0   PCI-MSI 368640-edge      PCIe PME, pciehp
  37:          0   PCI-MSI 370688-edge      PCIe PME, pciehp
  38:          0   PCI-MSI 372736-edge      PCIe PME, pciehp
  39:          0   PCI-MSI 374784-edge      PCIe PME, pciehp
  40:          0   PCI-MSI 376832-edge      PCIe PME, pciehp
  41:          0   PCI-MSI 378880-edge      PCIe PME, pciehp
  42:          0   PCI-MSI 380928-edge      PCIe PME, pciehp
  43:          0   PCI-MSI 382976-edge      PCIe PME, pciehp
  44:          0   PCI-MSI 385024-edge      PCIe PME, pciehp
  45:          0   PCI-MSI 387072-edge      PCIe PME, pciehp
  46:          0   PCI-MSI 389120-edge      PCIe PME, pciehp
  47:          0   PCI-MSI 391168-edge      PCIe PME, pciehp
  48:          0   PCI-MSI 393216-edge      PCIe PME, pciehp
  49:          0   PCI-MSI 395264-edge      PCIe PME, pciehp
  50:          0   PCI-MSI 397312-edge      PCIe PME, pciehp
  51:          0   PCI-MSI 399360-edge      PCIe PME, pciehp
  52:          0   PCI-MSI 401408-edge      PCIe PME, pciehp
  53:          0   PCI-MSI 403456-edge      PCIe PME, pciehp
  54:          0   PCI-MSI 405504-edge      PCIe PME, pciehp
  55:          0   PCI-MSI 407552-edge      PCIe PME, pciehp
  56:       7782   PCI-MSI 129024-edge      vmw_vmci
  57:          0   PCI-MSI 129025-edge      vmw_vmci
 NMI:          0   Non-maskable interrupts
 LOC:    3863622   Local timer interrupts
 SPU:          0   Spurious interrupts
 PMI:          0   Performance monitoring interrupts
 IWI:          0   IRQ work interrupts
 RTR:          0   APIC ICR read retries
 RES:          0   Rescheduling interrupts
 CAL:          0   Function call interrupts
 TLB:          0   TLB shootdowns
 TRM:          0   Thermal event interrupts
 THR:          0   Threshold APIC interrupts
 DFR:          0   Deferred Error APIC interrupts
 MCE:          0   Machine check exceptions
 MCP:        177   Machine check polls
 HYP:          0   Hypervisor callback interrupts
 HRE:          0   Hyper-V reenlightenment interrupts
 HVS:          0   Hyper-V stimer0 interrupts
 ERR:          0
 MIS:          0
 PIN:          0   Posted-interrupt notification event
 NPI:          0   Nested posted-interrupt event
 PIW:          0   Posted-interrupt wakeup event

1.5 /proc/iomem

There’s also a file here called /proc/iomem which contains a list of I/O port assignments on the system.

# cat /proc/iomem 
00000000-00000fff : Reserved
00001000-0009ebff : System RAM
0009ec00-0009ffff : Reserved
000a0000-000bffff : PCI Bus 0000:00
000c0000-000c7fff : Video ROM
000ca000-000cafff : Adapter ROM
000cc000-000cffff : PCI Bus 0000:00
000d0000-000d3fff : PCI Bus 0000:00
000d4000-000d7fff : PCI Bus 0000:00
000d8000-000dbfff : PCI Bus 0000:00
000dc000-000fffff : Reserved
  000f0000-000fffff : System ROM
00100000-3fedffff : System RAM
  1aa00000-1b6013f0 : Kernel code
  1b6013f1-1be19eff : Kernel data
  1c5ad000-1cbfffff : Kernel bss
  2a000000-33ffffff : Crash kernel
3fee0000-3fefefff : ACPI Tables
3feff000-3fefffff : ACPI Non-volatile Storage
3ff00000-3fffffff : System RAM

1.6 /proc/modules

Another very useful file is the /proc/modules file, this file contains a list of all the kernel modules currently being used by the system.

An example of a /proc/modules file is shown here.

I’ve just used the cat command to view it and here you can see all the various kernel modules that have been loaded such as our bluetooth driver which is used to provide support for Bluetooth devices in the system.

# cat /proc/modules
uinput 20480 1 - Live 0xffffffffc0adb000
fuse 131072 3 - Live 0xffffffffc0a3d000
rfcomm 86016 6 - Live 0xffffffffc0871000
xt_CHECKSUM 16384 1 - Live 0xffffffffc0a34000
ipt_MASQUERADE 16384 1 - Live 0xffffffffc0a2f000
xt_conntrack 16384 1 - Live 0xffffffffc0a2a000
ipt_REJECT 16384 1 - Live 0xffffffffc0a23000
nft_counter 16384 16 - Live 0xffffffffc0a1e000
nf_nat_tftp 16384 0 - Live 0xffffffffc0a19000
nft_objref 16384 1 - Live 0xffffffffc0a14000
nf_conntrack_tftp 16384 3 nf_nat_tftp, Live 0xffffffffc0a0f000
tun 53248 1 - Live 0xffffffffc0a01000
bridge 192512 0 - Live 0xffffffffc09cf000
stp 16384 1 bridge, Live 0xffffffffc09ca000
llc 16384 2 bridge,stp, Live 0xffffffffc09c5000
bluetooth 634880 27 rfcomm,bnep,btusb,btrtl,btbcm,btintel, Live 0xffffffffc05a9000
ecdh_generic 24576 1 bluetooth, Live 0xffffffffc051f000
rfkill 28672 5 bluetooth, Live 0xffffffffc02ba000

1.7 /proc/scsi/ Directory explained

There is a subfolder here named scsi.

The scsi directory contains additional files that contain information about the various scsi devices on your system.

# ls /proc/scsi/
device_info  mptspi  scsi  sg
# cat /proc/scsi/scsi 
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 02
Host: scsi0 Channel: 00 Id: 01 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 02
Host: scsi0 Channel: 00 Id: 02 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 02
Host: scsi0 Channel: 00 Id: 03 Lun: 00
  Vendor: VMware,  Model: VMware Virtual S Rev: 1.0 
  Type:   Direct-Access                    ANSI  SCSI revision: 02
Host: scsi2 Channel: 00 Id: 00 Lun: 00
  Vendor: NECVMWar Model: VMware IDE CDR10 Rev: 1.00
  Type:   CD-ROM                           ANSI  SCSI revision: 05

1.8 /proc/bus/ Directory explained

There’s also a folder over here called bus, within bus is a file named devices which contains information about the various USB devices on the system.

# ls /proc/bus/
input  pci

# ls /proc/bus/input/
devices  handlers
# cat devices
I: Bus=0019 Vendor=0000 Product=0001 Version=0000
N: Name="Power Button"
P: Phys=LNXPWRBN/button/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXPWRBN:00/input/input0
U: Uniq=
H: Handlers=kbd event0 
B: PROP=0
B: EV=3
B: KEY=10000000000000 0

I: Bus=0011 Vendor=0001 Product=0001 Version=ab41
N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input1
U: Uniq=
H: Handlers=sysrq kbd leds event1 
B: PROP=0
B: EV=120013
B: KEY=402000000 3803078f800d001 feffffdfffefffff fffffffffffffffe
B: MSC=10
B: LED=7

I: Bus=0011 Vendor=0002 Product=0013 Version=0006
N: Name="VirtualPS/2 VMware VMMouse"
P: Phys=isa0060/serio1/input1
S: Sysfs=/devices/platform/i8042/serio1/input/input4
U: Uniq=
H: Handlers=mouse0 event2 
B: PROP=0
B: EV=b
B: KEY=70000 0 0 0 0
B: ABS=3

1.9 /proc/diskstats

The /proc/diskstats file displays the I/O statistics of block devices. Each line contains the following 14 fields:

  1. Major number
  2. Minor number
  3. Device name
  4. Reads completed successfully
  5. Reads merged
  6. Sectors read
  7. Time spent reading (ms)
  8. Writes completed
  9. Writes merged
  10. Sectors written
  11. time spent writing (ms)
  12. I/Os currently in progress
  13. Time spent doing I/Os (ms)
  14. Weighted time spent doing I/Os (ms)

An example of a /proc/diskstats file is shown here.

# cat /proc/diskstats
   8       0 sda 364602 84167 34602359 214193 42116 376022 4221929 47325 0 190620 134354 0 0 0 0
   8       1 sda1 599 0 100694 288 17 4 96 6 0 503 105 0 0 0 0
   8       2 sda2 142790 83948 1850352 77867 21907 373586 3163944 32211 0 79272 61332 0 0 0 0
   8       3 sda3 221046 219 32616689 135978 20192 2432 1057889 15107 0 130180 72903 0 0 0 0
   8      16 sdb 7248 0 486546 961 698 830 350550 307 0 3220 164 0 0 0 0
   8      17 sdb1 435 0 28880 80 127 83 50841 57 0 347 30 0 0 0 0
   8      18 sdb2 414 0 29288 34 23 0 1915 4 0 168 3 0 0 0 0
   8      19 sdb3 454 0 28576 40 126 83 50833 55 0 260 22 0 0 0 0
   8      32 sdc 2201 0 163248 265 131 0 11523 53 0 1213 41 0 0 0 0
   8      48 sdd 1609 0 137440 212 129 0 11507 57 0 1086 36 0 0 0 0
  11       0 sr0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 253       0 dm-0 310 0 9616 51 189 0 49302 139 0 169 190 0 0 0 0
 253       1 dm-1 262 0 7528 29 189 0 49302 88 0 127 117 0 0 0 0

Source: kernel.org

1.10 /proc/swaps

/proc/swaps measures swap space and its utilization.

This file provides a snapshot of every swap file name, the type of swap space, the total size, and the amount of space in use (in kilobytes).

# cat /proc/swaps
Filename				Type		Size	Used	Priority
/dev/sda2                               partition	2097148	718592	-2

Suggested Read: How to create swap partition in Linux

1.11 /proc/filesystems

/proc/filesystems file displays a list of the file system types currently supported by the kernel.

# cat /proc/filesystems
nodev	sysfs
nodev	rootfs
nodev	ramfs
nodev	bdev
nodev	proc
nodev	cpuset
nodev	cgroup
nodev	cgroup2
nodev	tmpfs
nodev	devtmpfs
nodev	configfs
nodev	debugfs
nodev	tracefs
nodev	securityfs
nodev	sockfs
nodev	bpf
nodev	pipefs
nodev	hugetlbfs
nodev	devpts
nodev	autofs
nodev	pstore
nodev	mqueue
nodev	selinuxfs
	xfs
	ext3
	ext2
	ext4
nodev	rpc_pipefs
	fuseblk
nodev	fuse
nodev	fusectl

1.12 /proc/partitions

/proc/partitions: This file contains partition block allocation information.

# cat /proc/partitions
major minor  #blocks  name

   8        0   20971520 sda
   8        1     307200 sda1
   8        2    2097152 sda2
   8        3   18566144 sda3
   8       16    3145728 sdb
   8       17     512000 sdb1
   8       18     512000 sdb2
   8       19     512000 sdb3
   8       32    3145728 sdc
   8       48    3145728 sdd
  11        0    1048575 sr0
 253        0     512000 dm-0
 253        1     512000 dm-1

Suggested Read:

1.13 /proc/meminfo

This is one of the more commonly used files in the /proc directory, as it reports a large amount of valuable information about the system’s RAM usage.

# cat meminfo 
MemTotal:         810492 kB
MemFree:           85700 kB
MemAvailable:     141600 kB
Buffers:              64 kB
Cached:           148356 kB
SwapCached:        59496 kB
Active:           214320 kB
Inactive:         178792 kB
Active(anon):     130152 kB
Inactive(anon):   125584 kB
Active(file):      84168 kB
Inactive(file):    53208 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       2097148 kB
SwapFree:        1371388 kB
Dirty:                32 kB
Writeback:             0 kB
AnonPages:        237956 kB
Mapped:            64296 kB
Shmem:             11044 kB
KReclaimable:      55044 kB
Slab:             166788 kB
SReclaimable:      55044 kB
SUnreclaim:       111744 kB
KernelStack:       11436 kB
PageTables:        49720 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     2502392 kB
Committed_AS:    4800280 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
Percpu:            57856 kB
HardwareCorrupted:     0 kB
AnonHugePages:     81920 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:      286592 kB
DirectMap2M:      761856 kB
DirectMap1G:           0 kB

1.14 /proc/uptime

This file contains information detailing how long the system has been on since its last restart.

# cat /proc/uptime 
69274.12 67735.13

1.15 /proc/version

This file specifies the version of the Linux kernel, the version of gcc used to compile the kernel, and the time of kernel compilation. It also contains the kernel compiler’s user name.

# cat /proc/version 
Linux version 4.18.0-193.el8.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC)) #1 SMP Fri May 8 10:59:10 UTC 2020

You can also get the same information using the uname command.

# uname -a
Linux localhost.localdomain 4.18.0-193.el8.x86_64 #1 SMP Fri May 8 10:59:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

2. Exploring /sys File System

Now in addition to the /proc directory there’s another directory within your Linux file system named /sys and it also provides information about the hardware installed in the system.

Now the file system within /sys actually organized into a kind of tree structure that’s grouped by the hardware bus, the hardware devices and their associated drivers.

The top level of the /sys directory is shown here, and it contains many subdirectories to organize this information.

# ls /sys/
block  bus  class  dev  devices  firmware  fs  hypervisor  kernel  module  power

For example, the block directory contains a symbolic link file for each block device in the system.

2.1 /sys/bus/ Directory explained

The bus directory contains a directory for each data bus in the system such as your PCI bus, your scsi bus and your USB bus.

And then within each bus directory there are two subdirectories called devices and drivers.

# cd /sys/bus/

# ls
ac97  clockevents  cpu   event_source  i2c           memory    nvmem        platform  serio    thunderbolt  usb-serial  xen
acpi  clocksource  dax   gpio          machinecheck  mipi-dsi  pci          pnp       snd_seq  typec        virtio
cec   container    edac  hid           mdio_bus      node      pci_express  scsi      spi      usb          workqueue

# ls cpu/
devices  drivers  drivers_autoprobe  drivers_probe  uevent

# ls memory/
devices  drivers  drivers_autoprobe  drivers_probe  uevent

These are shown right here. I’m inside the USB bus directory.

# cd usb/

# ls
devices  drivers  drivers_autoprobe  drivers_probe  uevent

The devices subdirectory contains entries for every device connected to that bus while the drivers directory contains subdirectories for each driver that’s loaded for a given device on that bus.

2.2 Explaining /sys/class/, /sys/devices/, /sys/module/ Directories

Now within the /sys directory itself is a directory called class.

# ls /sys/
block  bus  class  dev  devices  firmware  fs  hypervisor  kernel  module  power

The /sys/class directory contains a listing of all device classes available.

The /sys/devices directory contains an entry for every hardware device that’s been discovered on the system.

There’s also directory here called /sys/module.

Now the /sys/module directory contains many subdirectories one for each module currently loaded into the kernel.

For example, here’s our sub directory for the Bluetooth kernel module, Mouse driver, subdirectory for our Keyboard driver and so on.

# cd /sys/module/

8250              debug_core             intel_rapl_common  nf_conntrack          nft_reject          slab_common         tpm_tis_core
ac97_bus          dm_mod                 intel_rapl_msr     nf_conntrack_ipv4     nft_reject_inet     snd                 ttm
acpi              drm                    intel_rapl_perf    nf_conntrack_ipv6     page_alloc          snd_ac97_codec      tun
acpiphp           drm_kms_helper         ip6_tables         nf_conntrack_tftp     pcie_aspm           snd_ens1371         uhci_hcd
ata_generic       dynamic_debug          ip_set             nf_defrag_ipv4        pciehp              snd_pcm             uinput
ata_piix          e1000                  ip_tables          nf_defrag_ipv6        pci_hotplug         snd_rawmidi         usbcore
battery           ecdh_generic           ipt_MASQUERADE     nf_nat                pcmcia_core         snd_seq             usbhid
blk_cgroup        edac_core              ipt_REJECT         nf_nat_ipv4           pcspkr              snd_seq_device      uv_nmi
block             efi_pstore             ipv6               nf_nat_ipv6           printk              snd_seq_midi        virtio_pci
bluetooth         efivars                jbd2               nf_nat_tftp           processor           snd_seq_midi_event  vmd
bnep              ehci_hcd               joydev             nfnetlink             psmouse             snd_timer           vmw_balloon
bridge            ext4                   kdb                nf_reject_ipv4        pstore              soundcore           vmwgfx
btbcm             fb                     kernel             nf_reject_ipv6        random              spurious            vmw_vmci
btintel           fb_sys_fops            keyboard           nf_tables             rcupdate            srcutree            vmw_vsock_vmci_transport
btrtl             firmware_class         kgdboc             nf_tables_set         rcutree             sr_mod              vsock
btusb             fuse                   kgdbts             nft_chain_nat_ipv4    rfcomm              stp                 vt
button            ghash_clmulni_intel    libata             nft_chain_nat_ipv6    rfkill              sunrpc              watchdog
cdrom             haltpoll               libcrc32c          nft_chain_route_ipv4  rng_core            suspend             workqueue
cec               hid                    llc                nft_chain_route_ipv6  rtc_cmos            syscopyarea         xfs
configfs          hid_magicmouse         mbcache            nft_compat            scsi_dh_alua        sysfillrect         xhci_hcd
cpufreq           hid_ntrig              md_mod             nft_counter           scsi_dh_rdac        sysimgblt           xt_CHECKSUM
cpuidle           i2c_piix4              module             nft_ct                scsi_mod            sysrq               xt_conntrack
crc32c_intel      i8042                  mousedev           nft_fib               scsi_transport_spi  tcp_cubic           xz_dec
crc32_pclmul      ima                    mptbase            nft_fib_inet          sd_mod              thermal             zswap
crc_t10dif        intel_idle             mptscsih           nft_fib_ipv4          serio_raw           tpm
crct10dif_pclmul  intel_pmc_core         mptspi             nft_fib_ipv6          sg                  tpm_crb
cryptomgr         intel_pmc_core_pltdrv  netpoll            nft_objref            shpchp              tpm_tis

3. Commands to Check Hardware Information on Linux

Now in addition to the /proc and /sys directories most Linux distributions also provide a wide variety of command-line tools that you can use to view information about the hardware currently installed in your system.

And if you want to know the truth a lot of these tools actually just pull their information right out of the /proc directly.

Now be aware that many of the commands we’re going to look at here may not actually be installed by default with some distributions.

However, if it’s not installed you can usually go out and get them manually using either the yum or apt-get commands.

Let’s take a look at what some of these utilities are.

3.1 hdparm Command: Get SATA/IDE device parameters

The first one we need to look at is the hdparm command.

It’s used to display information about your hard disk drive, the syntax is to enter hdparm and then specify which hard disk device file we want to view information about.

Syntax: hdparm [options] [device …] / hdparm /dev/device

We would replace this with something like sda or sdb whichever device we want to view information about and when you do data about that device is displayed on the screen.

In this case I’m looking at information about the /dev/sda hard disk drive.

# hdparm /dev/sda

/dev/sda:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 multcount     =  0 (off)
 readonly      =  0 (off)
 readahead     = 8192 (on)
 geometry      = 2610/255/63, sectors = 41943040, start = 0

3.2 sg_scan Command: Scans SCSI/ATAPI/ATA devices

The next utility you need to be familiar with is the sg_scan utility.

It’s used to scan your scsi buses and list all the devices that are connected to your scsi controllers.

# sg_scan
/dev/sg0: scsi0 channel=0 id=0 lun=0
/dev/sg1: scsi0 channel=0 id=1 lun=0
/dev/sg2: scsi0 channel=0 id=2 lun=0
/dev/sg3: scsi0 channel=0 id=3 lun=0
/dev/sg4: scsi2 channel=0 id=0 lun=0 [em]

3.3 sginfo Command: Access mode page information for a SCSI (or ATAPI) device

A similar command is the sginfo -l command.

It’s also used to display information about all the scsi devices in your system.

# sginfo -l

/dev/sg0 [scsi0 ch=0 id=0 lun=0]
/dev/sg1 [scsi0 ch=0 id=1 lun=0]
/dev/sg2 [scsi0 ch=0 id=2 lun=0]
/dev/sg3 [scsi0 ch=0 id=3 lun=0]
/dev/sg4 [scsi2 ch=0 id=0 lun=0]

3.4 lsusb Command: List USB devices

Another useful command is the lsusb command.

It displays information about all the USB devices that are currently connected to your system.

When you run it, you can see a listing of all your USB buses and all of the devices that are connected to that bus.

# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 009: ID 0e0f:0008 VMware, Inc. 
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

In this example, I can see that I have two different USB buses, I have Bus 001 and then I have Bus 002.

On Bus 001 all I have is a root hub on Bus 002 I have a root hub and then I have another USB hub and then I have a mouse.

3.5 hwinfo Command: Probe for hardware

Another useful utility is the hwinfo utility.

# hwinfo

It displays a comprehensive overview of all the system hardware in your system.

It will probe the system hardware and then generate a system overview report.

Now if you don’t specify any options with the command it will produce a very long report.

So, what we usually do is limit the report to a single device subsystem using the --device option.

Now you can replace device here with a variety of different types of devices you need to.

Syntax: hwinfo --device

Here is an example, Type the following command to display Network card information.

# hwinfo --short --netcard

Note: hwinfo command is not installed by default on a lot of distributions but you can usually go out and get it and install it with yum, zipper or apt-get.

3.6 lspci Command: List all PCI devices

The next command we’re going to look at here is lspci, this lists all of the PCI devices installed with the system.

When you use the -k option then the lspci command will also list the kernel modules associated with each PCI device.

You can see an example of doing that here.

# lspci -k
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)
	Subsystem: VMware Virtual Machine Chipset
00:01.0 PCI bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX AGP bridge (rev 01)
00:07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)
	Subsystem: VMware Virtual Machine Chipset
00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
	Subsystem: VMware Virtual Machine Chipset
	Kernel driver in use: ata_piix
	Kernel modules: ata_piix, ata_generic
00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
	Subsystem: VMware Virtual Machine Chipset
	Kernel modules: i2c_piix4
00:07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10)
	Subsystem: VMware Virtual Machine Communication Interface
	Kernel driver in use: vmw_vmci
	Kernel modules: vmw_vmci

3.7 lscpu Command: Display information about the CPU architecture

The lscpu command reports information about the CPU and Processing Units.

# lscpu 
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              1
On-line CPU(s) list: 0
Thread(s) per core:  1
Core(s) per socket:  1
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               78
Model name:          Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz
Stepping:            3
CPU MHz:             2495.999
BogoMIPS:            4991.99
Hypervisor vendor:   VMware
Virtualization type: full
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            3072K
NUMA node0 CPU(s):   0

3.8 lsscsi Command: List SCSI devices

Lists out the SCSI/SATA devices such as hard drives and optical drives.

# lsscsi 
[0:0:0:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sda 
[0:0:1:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sdb 
[0:0:2:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sdc 
[0:0:3:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sdd 
[2:0:0:0]    cd/dvd  NECVMWar VMware IDE CDR10 1.00  /dev/sr0 

3.9 lsblk Command: List block devices

Lists all block devices, such as the hard drive partitions, Logical Volumes (LVM) and other storage devices like optical drives and flash drives.

# lsblk 
NAME                    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                       8:0    0   20G  0 disk 
├─sda1                    8:1    0  300M  0 part /boot
├─sda2                    8:2    0    2G  0 part [SWAP]
└─sda3                    8:3    0 17.7G  0 part /
sdb                       8:16   0    3G  0 disk 
├─sdb1                    8:17   0  500M  0 part 
│ └─new_vgroup-newlv001 253:0    0  500M  0 lvm  /newlv001
├─sdb2                    8:18   0  500M  0 part 
│ ├─new_vgroup-newlv001 253:0    0  500M  0 lvm  /newlv001
│ └─new_vgroup-newlv002 253:1    0  500M  0 lvm  /newlv002
└─sdb3                    8:19   0  500M  0 part 
  └─new_vgroup-newlv002 253:1    0  500M  0 lvm  /newlv002
sdc                       8:32   0    3G  0 disk 
sdd                       8:48   0    3G  0 disk 
sr0                      11:0    1 1024M  0 rom

3.10 free Command: Display amount of free and used memory in the system

free Command displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo.

# free
              total        used        free      shared  buff/cache   available
Mem:         810492      484516      107052        4480      218924      185472
Swap:       2097148      792320     1304828

Conclusion

I hope you have learned something from this article.

I have tried my best to include all the Useful Commands to check System and Hardware Information in Linux

Now I’d like to hear your thoughts.

Was this guide useful to you?

Or maybe you have some queries.

Have I not included any command in this guide?

Leave a comment below.

Source: https://access.redhat.com/

Exit mobile version