1. Introduction

Often, we need to get information about the hardware that is running a system. Linux provides multiple ways to access different kinds of data about the hardware from the command line.

In this tutorial, we’ll look at many ways to get the specifications of the CPU, RAM, disks, and peripheral devices.

2. The /proc Pseudo-filesystem

In Linux, proc is a pseudo-filesystem mounted at /proc. It contains information about the kernel parameters. This filesystem exists only in the memory when the system is running and is not persisted on the disk.

Running ls on the /proc folder will give us a big list of virtual files and directories:

$ ls /proc
1     buddyinfo  cpuinfo    execdomains  irq        kpagecgroup  meminfo  pagetypeinfo  stat         tty
13    bus        crypto     filesystems  kallsyms   kpagecount   misc     partitions    swaps        uptime
7     cgroups    devices    fs           kcore      kpageflags   modules  sched_debug   sys          version
8     cmdline    diskstats  interrupts   keys       loadavg      mounts   schedstat     sysvipc      vmallocinfo
9     config.gz  dma        iomem        key-users  locks        mtrr     self          thread-self  vmstat
acpi  consoles   driver     ioports      kmsg       mdstat       net      softirqs      timer_list   zoneinfo

Some notable files include cpuinfo, meminfo, and devices. These files contain information about the system hardware, and we will use them in the sections below.

3. Processor (CPU)

We can use various commands to get CPU information, such as:

  • architecture
  • number of cores
  • clock speed

Some involve commands, while others are built-in.

3.1. Using uname

To begin with, the uname command gives us basic information about the CPU architecture. In general, uname can be used to get various details pertaining to the operating system, kernel, and processors. Running uname -a prints all the available details:

$ uname -a
Linux dell 5.11.0-38-generic #42~20.04.1-Ubuntu SMP Tue Sep 28 20:41:07 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

To get just what we need, we can use the -p flag instead, which stands for “processor”:

$ uname -p
x86_64

Here, we see output for a 64-bit CPU.

3.2. Querying /proc

We can read the contents of the /proc/cpuinfo file to get information about the CPU. This method lists all the available CPU cores with detailed information about each:

$ cat /proc/cpuinfo
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 69
model name	: Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
stepping	: 1
microcode	: 0x26
cpu MHz		: 800.000
cache size	: 3072 KB
physical id	: 0
siblings	: 4
core id		: 0
cpu cores	: 2
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
vmx flags	: vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips	: 3392.19
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:
...

This system has an Intel i5 CPU, providing the outlined features. Moreover, we get information about each of its cores.

3.3. Using lscpu

For a neat summary of all related information, we can use the lscpu command. It gathers this information from the sysfs pseudo-filesystem and /proc/cpuinfo, which it organizes in a more readable format:

$ lscpu
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   39 bits physical, 48 bits virtual
CPU(s):                          4
On-line CPU(s) list:             0-3
Thread(s) per core:              2
Core(s) per socket:              2
Socket(s):                       1
NUMA node(s):                    1
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           69
Model name:                      Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
Stepping:                        1
CPU MHz:                         2018.999
CPU max MHz:                     2700.0000
CPU min MHz:                     800.0000
BogoMIPS:                        3392.19
Virtualization:                  VT-x
...

We see information about ArchitectureByte Order, Thread(s) per core, and others. Also, lscpu prints a brief summary, compared to the one-section-per-core format of /proc/cpuinfo.

Further, we can use grep or other text processing commands to filter the output and get only what we need:

$ lscpu | grep 'Model name'
Model name:                      Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz

There are also flags available to modify the output of lscpu. The -e flag, for example, prints the output in a tabular format.

4. Main Memory (RAM)

There are many ways to analyze the memory usage on Linux, and most of these methods also tell us about the total memory available to the system.

4.1. Querying /proc

An easy way to get the total available memory as seen by the system is to read the contents of the /proc/meminfo file:

$ cat /proc/meminfo
MemTotal:        3929792 kB
MemFree:          662148 kB
MemAvailable:    1949468 kB
Buffers:          294628 kB
Cached:          1325680 kB
SwapCached:        93864 kB
Active:           798952 kB
...

We see above that the file contains many details like Buffers, SwapCached memory, and others. To find only the line we need, we can use grep:

$ grep MemTotal /proc/meminfo
MemTotal:        3929792 kB

Now only the MemTotal line is printed.

4.2. Using free

The free command provides data about the total memory available and the memory used. It prints the output in bytes by default. We use the -h flag to get output in a human-readable format:

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          3.7Gi       1.9Gi       517Mi       282Mi       1.3Gi       1.3Gi
Swap:         2.0Gi       147Mi       1.9Gi

This system has 3.7Gi of RAM, out of which 1.9Gi is in use.

4.3. Using top

The top command is also handy for getting the total memory, along with real-time monitoring of memory usage:

$ top
top - 07:31:46 up 43 min,  1 user,  load average: 0.25, 0.55, 0.66
Tasks: 206 total,   2 running, 204 sleeping,   0 stopped,   0 zombie
%Cpu(s):  8.7 us,  3.6 sy,  0.0 ni, 87.4 id,  0.3 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :   3837.7 total,    281.2 free,   1970.1 used,   1586.3 buff/cache
MiB Swap:   2048.0 total,   2037.2 free,     10.8 used.   1357.5 avail Mem
...

The above output is for the same system, and we see similar total memory and used memory as with the free command. In both cases, Swap refers to the swap memory allocated from the disks and can be ignored for our current purpose.

To print the output once and then exit, we use top with the parameters -bn1. The -b flag stands for batch mode, while -n1 instructs the command to print one batch of output.

5. Secondary Storage (Disk)

A system usually has one or more storage devices attached, and these include hard disks, SSDs, and USB storage devices. We can use a variety of methods to list these devices and their partitions.

5.1. Querying /proc

To get information about the disks and their partitions, we can read the contents of the /proc/partitions file:

$ cat /proc/partitions
major minor  #blocks  name

   8        0  117220824 sda
   8        1     524288 sda1
   8        2          1 sda2
   8        5  116694016 sda5
   8       16  976762584 sdb
   8       17       1024 sdb1
   8       18  976758784 sdb2

From the above output, we see that the system has two connected disks, sda, and sdb, with three and two partitions, respectively.

5.2. Using lsblk

Running the lsblk command will supply a list of disks and their partitions in a neat tree representation. The command gathers this information from sysfs and udev db.

$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 111.8G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0     1K  0 part 
└─sda5   8:5    0 111.3G  0 part /
sdb      8:16   0 931.5G  0 disk 
├─sdb1   8:17   0     1M  0 part 
└─sdb2   8:18   0 931.5G  0 part

The output is similar to /proc/partitions but with a neat tabular structure and human-readable sizes.

5.3. Using hdparm

We can also run the hdparm command to get detailed information about each disk. It essentially provides command-line access to the kernel interfaces related to storage devices:

$ sudo hdparm -i /dev/sda

/dev/sda:

 Model=SATA SSD, FwRev=0200Sf10, SerialNo=00000000000000000552
 Config={ Fixed }
 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=0
 BuffType=unknown, BuffSize=unknown, MaxMultSect=16, MultSect=16
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=234441648
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes:  pio0 pio3 pio4 
 DMA modes:  mdma0 mdma1 mdma2 
 UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6 
 AdvancedPM=yes: disabled (255) WriteCache=enabled
 Drive conforms to: Unspecified:  ATA/ATAPI-3,4,5,6,7

 * signifies the current active mode

The output tells us that sda is a SATA SSD with the given raw cylinder-head-sector (CHD) metrics, among other things.

hdparm can also cause irreversible changes to the filesystem, such as formatting, and should be used with care.

6. PCI Devices

Intel developed the PCI standard in 1992 for connecting devices to the motherboard. It stands for Peripheral Component Interconnect. Here, we use the term PCI Devices to refer to devices such as audio cards and network cards that are directly connected to the motherboard via a PCI bus.

The lspci command prints information about the connected PCI devices:

$ lspci
00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 0b)
00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b)
00:03.0 Audio device: Intel Corporation Haswell-ULT HD Audio Controller (rev 0b)
00:14.0 USB controller: Intel Corporation 8 Series USB xHCI HC (rev 04)
00:16.0 Communication controller: Intel Corporation 8 Series HECI #0 (rev 04)
00:1b.0 Audio device: Intel Corporation 8 Series HD Audio Controller (rev 04)
00:1c.0 PCI bridge: Intel Corporation 8 Series PCI Express Root Port 1 (rev e4)
00:1c.2 PCI bridge: Intel Corporation 8 Series PCI Express Root Port 3 (rev e4)
00:1c.4 PCI bridge: Intel Corporation 8 Series PCI Express Root Port 5 (rev e4)
00:1d.0 USB controller: Intel Corporation 8 Series USB EHCI #1 (rev 04)
00:1f.0 ISA bridge: Intel Corporation 8 Series LPC Controller (rev 04)
00:1f.2 SATA controller: Intel Corporation 8 Series SATA Controller 1 [AHCI mode] (rev 04)
00:1f.3 SMBus: Intel Corporation 8 Series SMBus Controller (rev 04)
06:00.0 Network controller: Intel Corporation WiFi Link 5100
08:00.0 3D controller: NVIDIA Corporation GF117M [GeForce 610M/710M/810M/820M / GT 620M/625M/630M/720M] (rev a1)

We see various connected devices such as a network controller, a graphics card,  an audio device, and so on from the above output.

For more verbose output about each device, we can add the -v flag:

$ lspci -v
00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 0b)
	Subsystem: Dell Haswell-ULT DRAM Controller
	Flags: bus master, fast devsel, latency 0
	Capabilities: <access denied>
	Kernel driver in use: hsw_uncore

00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b) (prog-if 00 [VGA controller])
	Subsystem: Dell Haswell-ULT Integrated Graphics Controller
	Flags: bus master, fast devsel, latency 0, IRQ 53
	Memory at f7400000 (64-bit, non-prefetchable) [size=4M]
	Memory at d0000000 (64-bit, prefetchable) [size=256M]
	I/O ports at f000 [size=64]
	Expansion ROM at 000c0000 [virtual] [disabled] [size=128K]
	Capabilities: <access denied>
	Kernel driver in use: i915
	Kernel modules: i915
...

After including the -v flag in the command, we see that there are multiple lines of output per device, also containing the memory addresses of some devices. Further, using the -vv and -vvv flags instead of -v will give us progressively higher levels of verbosity in the output.

7. USB Devices

Universal Serial Bus or USB is another standard for connecting external devices to a computer, with much easier access in the form of external ports. Similar to PCI Devices, the lsusb command prints information about the connected USB devices:

$ lsusb
Bus 001 Device 005: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 001 Device 004: ID 0bda:5756 Realtek Semiconductor Corp. 
Bus 001 Device 007: ID 2e04:c026  
Bus 001 Device 006: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
Bus 001 Device 002: ID 8087:8000 Intel Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 003: ID 1c4f:0034 SiGma Micro Usb Mouse
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

In the above output, we see devices such as external keyboards and mice that are typically connected to the system via USB.

The -v flag works with lsusb too, if we need verbose output:

$ lsusb -v

Bus 001 Device 005: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          255 Vendor Specific Class
  bDeviceSubClass       255 Vendor Specific Subclass
  bDeviceProtocol       255 Vendor Specific Protocol
  bMaxPacketSize0        64
  idVendor           0x0bda Realtek Semiconductor Corp.
  idProduct          0x0129 RTS5129 Card Reader Controller
  bcdDevice           39.60
  iManufacturer           1 
  iProduct                2 
  iSerial                 3 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
...

The above output shows very detailed information per device instead of just device names, as we saw earlier. Here, we see the vendor (Realtek Semiconductor Corp.) of our RTS5129 Card Reader Controller.

Of course, it’s very useful to compare the outputs of the lsusb command with and without a particular device connected, to debug the device and the port.

8. Commands to List All Devices

In the previous sections, we saw separate ways to list different kinds of hardware devices. Now, we’ll look at some ways to list all the devices using single commands.

8.1. Using lshw

Finally, the lshw command lists all hardware devices. Used with the -short flag, it prints a brief list. Otherwise, it prints verbose information. Super-user privileges ensure the information is complete and accurate:

$ sudo lshw -short
H/W path         Device     Class          Description
======================================================
                            system         Inspiron 3542 (0652)
/0                          bus            0926J6
/0/0                        memory         64KiB BIOS
/0/1                        memory         4GiB System memory
/0/1/0                      memory         4GiB SODIMM DDR3 Synchronous 1600 MHz (0.6 ns)
/0/6                        memory         3MiB L3 cache
/0/5                        memory         512KiB L2 cache
/0/4                        memory         128KiB L1 cache
/0/24                       processor      Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
/0/100                      bridge         Haswell-ULT DRAM Controller
/0/100/2                    display        Haswell-ULT Integrated Graphics Controller
/0/100/3                    multimedia     Haswell-ULT HD Audio Controller
/0/100/14                   bus            8 Series USB xHCI HC
/0/100/14/0      usb2       bus            xHCI Host Controller
/0/100/14/0/1               input          Usb Mouse
/0/100/14/1      usb3       bus            xHCI Host Controller
/0/100/16                   communication  8 Series HECI #0
/0/100/1b                   multimedia     8 Series HD Audio Controller
/0/100/1c                   bridge         8 Series PCI Express Root Port 1
/0/100/1c.2                 bridge         8 Series PCI Express Root Port 3
/0/100/1c.2/0    wlp6s0     network        WiFi Link 5100
/0/100/1c.4                 bridge         8 Series PCI Express Root Port 5
/0/100/1c.4/0               display        GF117M [GeForce 610M/710M/810M/820M / GT 620M/625M/630M/720M]
/0/100/1d                   bus            8 Series USB EHCI #1
/0/100/1d/1      usb1       bus            EHCI Host Controller
/0/100/1d/1/1               bus            USB hub
/0/100/1d/1/1/2             input          USB Keyboard
/0/100/1d/1/1/3             generic        Nokia 2.3
/0/100/1d/1/1/5             multimedia     Integrated_Webcam_HD
/0/100/1d/1/1/8             generic        USB2.0-CRW
/0/100/1f                   bridge         8 Series LPC Controller
/0/100/1f.2                 storage        8 Series SATA Controller 1 [AHCI mode]
/0/100/1f.3                 bus            8 Series SMBus Controller
/0/2                        system         PnP device PNP0c01
/0/3                        system         PnP device PNP0c02
/0/7                        system         PnP device PNP0b00
/0/8                        generic        PnP device INT3f0d
/0/9                        system         PnP device PNP0c02
/0/a                        input          PnP device PNP0303
/0/b                        system         PnP device PNP0c02
/0/c                        system         PnP device PNP0c02
/0/d             scsi0      storage        
/0/d/0.0.0       /dev/sda   disk           120GB SATA SSD
/0/d/0.0.0/1     /dev/sda1  volume         512MiB Windows FAT volume
/0/d/0.0.0/2     /dev/sda2  volume         111GiB Extended partition
/0/d/0.0.0/2/5   /dev/sda5  volume         111GiB EXT4 volume
/0/e             scsi1      storage        
/0/e/0.0.0       /dev/sdb   disk           1TB ST1000LM024 HN-M
/0/e/0.0.0/1     /dev/sdb1  volume         1023KiB EFI partition
/0/e/0.0.0/2     /dev/sdb2  volume         931GiB EXT4 volume
/1                          power          DELL 49VTP27

In the output above, we see that all devices from the above sections – CPUs, RAM, disks, and peripheral devices are grouped together in a single list.

8.2. Using dmidecode

Another option to get similar output is the dmidecode command, which lists all the hardware as seen by the DMI interface. DMI stands for Desktop Management Interface. Computers store a low-level DMI table with information about the hardware. The dmidecode command dumps the content of this DMI table in a neat format:

$ sudo dmidecode | head -n 20
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.
45 structures occupying 2092 bytes.
Table at 0x000EC720.

Handle 0xDA00, DMI type 218, 251 bytes
OEM-specific Type
	Header and Data:
		DA FB 00 DA B2 00 0D 5F 0F 37 40 7D 00 00 00 00
		00 7E 00 01 00 00 00 75 01 01 80 01 00 76 01 02
		80 01 00 2D 01 03 80 01 00 2E 01 04 80 00 00 4F
		02 05 80 01 00 50 02 06 80 00 00 E2 01 02 00 00
...

From the above output, we see that the dmidecode command contains information that is not very human-readable, such as headers.

The output of dmidecode is very verbose, best used during debugging. To get output for a specific type of device, we can use the -t flag followed by the type number or type name:

$ sudo dmidecode -t 22
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x0015, DMI type 22, 26 bytes
Portable Battery
	Location: Sys. Battery Bay
	Manufacturer: LGC-LGC3.0         
	Serial Number: 14057        
	Name: DELL 49VTP27
	Chemistry: Lithium Ion
	Design Capacity: 44000 mWh
	Design Voltage: 11100 mV
	SBDS Version: 1.0                
	Maximum Error: 2%
	SBDS Manufacture Date: 2018-06-29
	OEM-specific Information: 0x00000001

The example above shows the output for “portable battery”, which is type number 22. Every type name has an assigned type number.

9. Conclusion

In this tutorial, we looked at various commands to list and get information about hardware devices connected to a system. This includes CPUs, RAM, hard disks, PCI, and USB devices. This information can help us in various situations, most importantly for debugging devices when something doesn’t work as expected.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.