13 Linux Commands to Monitor Hardware and System Resources

Linux, one of the most popular operating systems, offers multiple command-line tools to collect hardware and system information that can be used to monitor system resources.

In this post, I will go over 12 such command line too, that provide essential information to maintain performance and diagnose issues.

So, let’s dive in and explore these commands with actual examples by running them on Ubuntu Linux.

1. df: Disk Filesystem Usage Information tool

The df command, is used for checking disk space usage on Linux systems. It provides an overview of storage usage as well as total capacity for each device and partition.

You can use df command for regular maintenace or for monitoring real-time disk usage to avoid disk space not available issues.

To get information on all availabled (or mounted) filesystem just enter the df command on the terminal (or shell), as shown below.

root@slap:~# df

Filesystem      1K-blocks      Used  Available Use% Mounted on
/dev/sdb        263174212   3527192  246208864   2% /
tmpfs            13012624         0   13012624   0% /mnt/wsl
tools           976427004 253349576  723077428  26% /init
none             13012624         8   13012616   1% /run
none             13012624         0   13012624   0% /run/lock
none             13012624         0   13012624   0% /run/shm
none             13012624         0   13012624   0% /run/user
tmpfs            13012624         0   13012624   0% /sys/fs/cgroup
drivers         976427004 253349576  723077428  26% /usr/lib/wsl/drivers
lib             976427004 253349576  723077428  26% /usr/lib/wsl/lib

In the output above you can get information on all available partitions, showing information about total and available disk space. Percentage used is also shown next to the mount point.

Man page link: df.

2. dmidecode: DMI Table Decoder

dmidecode is a tool for reading the computer’s Desktop Management Interface (DMI or SMBIOS) table data in a human-readable format. The DMI table maintains information about the system’s hardware componets including serial numbers and BIOS version.

Usage: Type ‘dmidecode’ in the terminal and press Enter. To narrow down the output to specific hardware components, use ‘dmidecode -t [type]’ or ‘dmidecode –type [type]’. You may need root privileges to access the information; in that case, use ‘sudo dmidecode’.

# dmidecode 3.3
Getting SMBIOS data from sysfs.
SMBIOS 2.7 present.
620 structures occupying 29828 bytes.
Table at 0x000E0010.

Handle 0x0000, DMI type 0, 24 bytes
BIOS Information
  Vendor: Phoenix Technologies LTD
  Version: 6.00
  Release Date: 11/12/2020
  Address: 0xEA480
  Runtime Size: 88960 bytes
  ROM Size: 64 kB
  Characteristics:
    ISA is supported
    PCI is supported
    PC Card (PCMCIA) is supported
    PNP is supported
    APM is supported
    BIOS is upgradeable
    BIOS shadowing is allowed
    ESCD support is available
    Boot from CD is supported
    Selectable boot is supported
    EDD is supported

--- Rest of output truncated ---

Dmidecode can output a large amount of data. To display information about specific hardware components, use the ‘-t’ or ‘–type’ option followed by a DMI type number or keyword.:

  • BIOS: Displays BIOS information. Use command option sudo dmidecode -t bios.
  • Memory: Displays memory module information. Use command option sudo dmidecode -t processor.
  • Processor: Displays CPU information. Use command option”sudo dmidecode -t processor.

For details of available options check out dmidecode man page.

Man page link: dmidecode.

3. fdisk: Partition table manipulator for Linux

fdisk utility helps to manage disk partitions on a Linux system. It allows users to view, create, resize, delete, and modify partitions, as well as display partition information.

Although not directly an analytics tool, fdisk can provide useful information for an admin to manage disk space allocations.

To view a list of all available storage devices and their partitions, use the -l option followed by the sudo command:

fdisk [options] [device]

To view, all available storage devices use the following command.

disk -l

The output will provide a list of all mounted devices with storage capacities and other metadata. Show below is the detail of one of the devices from the command above.

Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: xyz
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: CD2E4881-9C10-4706-9A61-F1BA7A4B555A

Device       Start       End   Sectors  Size Type
/dev/sda1     2048      4095      2048    1M BIOS boot
/dev/sda2     4096   1054719   1050624  513M EFI System
/dev/sda3  1054720 104855551 103800832 49.5G Linux filesystem

To work with a specific device you can use the fdisk command along with the device path. Let’s say I want to manage the device /dev/sda then I will have to enter the following command.

ser@d1:~$ sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): 

This will bring me an interactive mode where I can enter m to see all available options.

Unless you know exactly what you are doing, do not try to modify the active disk as it may damage your operating system.

Man page link: fdisk.

4. free: Display Amount of Free and Used Memory

The free command is a simple yet invaluable tool for Linux users seeking to monitor and manage their system’s memory usage. It displays information about the total, used, and available memory. The types of memory it can report include, physical RAM, swap space, and buffer/cache memory.

To get information on memory with totals, use the following:

user@d1:~$ free -t
               total        used        free      shared  buff/cache   available
Mem:         3982136     2481304      196044       49560     1304788     1216348
Swap:        3991548       10568     3980980
Total:       7973684     2491872     4177024

You can further customize the output by displaying memory usage by KiloBytes, MegaBytes and GigaBytes using the options -k, -m and -g respectively.

Using free with auto-update: Use the option -s [delay], you can get free to report memory usage statistics that are updated every X seconds.

Man page link: free.

5. hdparm: get/set SATA/IDE/NVMe device parameters

hdparm is a command-line utility used for interacting with SATA, IDE, and NVMe storage devices on Linux systems. It enables you to gather information about your hard disk drives and solid-state drives, such as performance metrics, device identification, power management settings, and other device-specific features.

You can also use the hdparm command to measure disk performance.

The basic syntax for hdparm is as follows:

hdparm [options] [device]

Where options are the flags you want to use, and device is the path to the target storage device (e.g., /dev/sda).

Some commonly used options are:

  • -I: Display detailed drive information
  • -t: Perform a simple read test to measure disk performance
  • -T: Perform a cache read test to measure system buffer cache performance
  • -B: Get or set the Advanced Power Management (APM) feature

To display detailed information about a specific storage device, use the -I option:

user@d1:~$ sudo hdparm -I /dev/sda

/dev/sda:

ATA device, with non-removable media
Standards:
	Likely used: 1
Configuration:
	Logical		max	current
	cylinders	0	0
	heads		0	0
	sectors/track	0	0
	--
	Logical/Physical Sector size:           512 bytes
	device size with M = 1024*1024:           0 MBytes
	device size with M = 1000*1000:           0 MBytes 
	cache/buffer size  = unknown
Capabilities:
	IORDY not likely
	Cannot perform double-word IO
	R/W multiple sector transfer: not supported
	DMA: not supported
	PIO: pio0 

The output will show detailed information about the device, including the model number, serial number, firmware version, supported features, and capabilities.

If you want to To measure the disk performance, then use the -t and -T options together:

sudo hdparm -tT /dev/sda

Remember to exercise caution when using hdparm, as some options can lead to data loss or hardware damage if used improperly.

Man page link: hdparm

6. inxi: A System Information Script

inxi is a powerful and command-line utility that provides detailed hardware and system information on Linux. It can display information about the CPU, memory, storage devices, network interfaces, graphics, audio, and sensors.

To install inxi on your system with:

sudo apt install inxi

To get basic inforamtion about the system use the -b flag.

user@d1:~$ inxi -b

System:
  Host: d1 Kernel: 5.19.0-38-generic x86_64 bits: 64 Desktop: GNOME 42.5
    Distro: Ubuntu 22.04.2 LTS (Jammy Jellyfish)
Machine:
  Type: Windows v: N/A
    serial: <superuser required>
  Mobo: Intel model: 440BX Desktop Reference Platform
    serial: <superuser required> BIOS: Phoenix v: 6.00 date: 11/12/2020
CPU:
  Info: 2x 1-core AMD Ryzen Threadripper 1920X [SMP] speed (MHz): avg: 3494
Graphics:
  Device-1: VMware SVGA II Adapter driver: vmwgfx v: 2.20.0.0
  Display: wayland server: X.Org v: 1.22.1.1 with: Xwayland v: 22.1.1
    compositor: gnome-shell driver: gpu: vmwgfx resolution: 1440x900~60Hz
  OpenGL: renderer: SVGA3D; build: RELEASE; LLVM; v: 4.1 Mesa 22.2.5
Network:
  Device-1: Intel 82371AB/EB/MB PIIX4 ACPI type: network bridge driver: N/A
  Device-2: Intel 82545EM Gigabit Ethernet driver: e1000
Drives:
  Local Storage: total: 50 GiB used: 13.2 GiB (26.4%)
Info:
  Processes: 311 Uptime: 1h 29m Memory: 3.8 GiB used: 2.68 GiB (70.6%)
  Shell: Bash inxi: 3.3.13

You can specify other the following options for additional details or filtered output.

  • -F: Full output.
  • -C: Show CPU information only.
  • -G: Shows information about the graphics card and display.
  • -N: List network devices and their status.

Man page link: inxi.

7. lsblk: List Block Devices

The lsblk command is used to read information about block devices on your system. It can provide details about disk drives and partitions, such as their size, mount point, and filesystem type.

To get information about all available devices you can enter lsblk with any options.

user@d1:~$ lsblk -a
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0    50G  0 disk 
├─sda1   8:1    0     1M  0 part 
└─sda2   8:2    0   513M  0 part /boot/efi
                                 /
sr0     11:0    1 126.7M  0 rom  /media/user/CDROM
sr1     11:1    1   3.6G  0 rom  /media/user/Ubuntu 22.04.1 LTS amd64

Some common options are:

  • -a, --all: List all block devices, including empty devices.
  • -b, --bytes: Print sizes in bytes instead of a human-readable format.
  • -o, --output: Specify which columns to display in the output.
  • -P, --pairs: Display output as key-value pairs, useful for scripting purposes.
  • -S, --scsi: Display only SCSI devices.

By using lsblk, you can easily view crucial information about your Linux system’s disk drives and partitions, which can help you manage storage, diagnose issues, and plan for upgrades.

Man page link: lsblk.

8. lscpu: Display Information About CPU Architecture

The lscpu command is available for obtaining detailed information about your system’s Central Processing Unit (CPU). It displays essential data such as architecture, number of cores, threads, cache sizes, and more.

The basic syntax for the ‘lscpu’ command is straightforward:

lscpu [options]

Several options can be used to modify the output or filter the information displayed:

  • -a, --all: Show all CPUs (default behavior).
  • -e, --extended[=LIST]: Display an extended readable format.
  • -p, --parse[=LIST]: Display the output in a parseable format.
  • -s, --sysroot=DIR: Retrieve CPU information from the specified system root directory.

To display basic CPU information, simply run the lscpu command without specifiying any options.

user@d1:~$ lscpu

Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         45 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  2
  On-line CPU(s) list:   0,1
Vendor ID:               AuthenticAMD
  Model name:            AMD Ryzen Threadripper 1920X 12-Core Processor
    CPU family:          23
    Model:               1
    Thread(s) per core:  1
    Core(s) per socket:  1
    Socket(s):           2
    Stepping:            1
    BogoMIPS:            6987.07
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse ss
                         e2 syscall nx mmxext pdpe1gb rdtscp lm constant_tsc rep_good nopl tsc_reliable nonstop_tsc cpui
                         d extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes
                          xsave avx f16c rdrand hypervisor lahf_lm cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw t
                         opoext ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveop
                         t xsavec xgetbv1 xsaves clzero arat overflow_recov succor
--- Additional output truncated ---

Man page link: lscpu.

9. lshw: List Hardware

The lshw command provides detailed information about your system’s hardware components. The lshw command gets hardware information from various sources, such as sysfs and /proc directory. It can display details about your CPU, memory, storage devices, network interfaces, and other hardware components.

To get information about all available hardware run the lshw command without any options as a root user.

root@mars:/home/sohail# lshw
mars
    description: Computer
    width: 64 bits
    capabilities: smp vsyscall32
  *-core
       description: Motherboard
       physical id: 0
     *-memory
          description: System memory
          physical id: 1
          size: 25GiB
     *-cpu
          product: AMD Ryzen Threadripper 1920X 12-Core Processor
          vendor: Advanced Micro Devices [AMD]
          physical id: 2
          bus info: cpu@0
          width: 64 bits
          capabilities: fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp x86-64 constant_tsc rep_good nopl tsc_reliable nonstop_tsc cpuid extd_apicid pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw topoext ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 xsaves clzero xsaveerptr virt_ssbd arat
     *-display
          description: 3D controller
          product: Microsoft Corporation
        
--- rest of ouput removed ---

Note: Above is the output when the command is run in the WSL Unbuntu terminal shell.

To get a shortened output from lshw, use the -short command line options.

root@mars:/# sudo lshw -short | more
H/W path    Device    Class      Description
============================================
                      system     Computer
/0                    bus        Motherboard
/0/1                  memory     25GiB System memory
/0/2                  processor  AMD Ryzen Threadripper 1920X 12-Core Processor
/0/0                  display    Microsoft Corporation
/0/3                  system     PnP device PNP0b00
/0/4        scsi0     storage
/0/4/0.0.0  /dev/sda  volume     256GiB Virtual Disk
/0/4/0.0.1  /dev/sdb  volume     256GiB Virtual Disk
/1          bond0     network    Ethernet interface
/2          dummy0    network    Ethernet interface
/3          eth0      network    Ethernet interface

The lshw command allows you to display information about specific hardware components by using class options.

  • lshw -class cpu: Displays information about the CPU
  • lshw -class memory: Displays information about memory modules, such as RAM and caches
  • lshw -class disk: Displays information about storage devices, such as hard drives and SSDs
  • lshw -class network: Displays information about network interfaces, like Ethernet or Wi-Fi adapters

Man page link: lshw.

10. lspci: List PCI Devices

The lspci command is used for displaying information about all Peripheral Component Interconnect (PCI) buses and devices on a system.

Using lspci you can find information about hardware components connected to the PCI bus. This will include information about graphics cards, network adapters, sound cards, and other devices. lspci is particularly helpful for diagnosing hardware compatibility issues, determining driver requirements, and troubleshooting problematic devices.

B. Syntax and usage:

The basic syntax for the lspci command is:

lspci [options]

Running lspci command without any options show the following on my Ubuntu system:

user@d1:~$ sudo lspci
00:00.0 Host bridge: Intel Corporation 440BX/ZX/DX - 82443BX/ZX/DX Host bridge (rev 01)
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)
00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00:07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
00:07.7 System peripheral: Virtual Machine Communication Interface (rev 10)
00:0f.0 VGA compatible controller: SVGA II Adapter
00:10.0 SCSI storage controller: Broadcom / LSI 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)
02:00.0 USB controller: USB1.1 UHCI Controller
02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)
02:02.0 Multimedia audio controller: Ensoniq ES1371/ES1373 / Creative Labs CT2518 (rev 02)
02:03.0 USB controller: VMware USB2 EHCI Controller
02:04.0 SATA controller: VMware SATA AHCI controller

There are several options available to customize the output of the lspci command:

  • -t or --tree: Shows the PCI devices in a tree-like diagram.
  • -n or --numeric: Displays the vendor and device codes as numbers.
  • -k or --kernel: Shows kernel driver information for each device.
  • -v or --verbose: Provides more detailed information about the devices.
  • -vv or --veryverbose: Displays even more details about the devices.
  • -nn or --nn: Displays both the numeric and human-readable vendor and device names.
  • -i or --file <file>: Uses an alternative PCI ID database file instead of the default one.

Man page link: lspci

11. lsusb: List USB Devices

The lsusb command displays information about Universal Serial Bus (USB) devices connected to your Linux system. The command helps you identify various USB devices such as external hard drives, flash drives, and printers.

The basic syntax for the lsusb command is:

lsusb [options]

Running the command on a VM install of Ubuntu shows the following output.

user@d1:~$ sudo lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 004: ID 0e0f:0008 Virtual Bluetooth Adapter
Bus 002 Device 003: ID 0e0f:0002 Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

There are several options available to customize the output of the lsusb command:

  • -t or --tree: Shows the USB devices in a tree-like diagram.
  • -v or --verbose: Provides more detailed information about the devices.
  • -s or --device <bus>:<device>: Displays information about a specific device on a specific bus.
  • -d or --device <vendor>:<product>: Shows information about devices with a specific vendor and product ID.

Man page link: lsusb

12. uname: Get Name and Information About Linux Kernel

uname is a versatile Linux command that provides essential information about your system’s software and hardware components. This command can give you details about the kernel name, version, release, and the hardware platform, among other things. It’s a handy tool for quickly determining your system’s basic specifications and gaining insight into the software environment.

The basic syntax for the uname command is:

uname [options]

To get all available information use the uname command with the -a options.

user@d1:~$ uname -a
Linux d1 5.19.0-38-generic #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 21:16:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

There are several options available to customize the output of the uname command:

  • -s or --kernel-name: Displays the kernel name.
  • -n or --nodename: Shows the network node hostname.
  • -r or --kernel-release: Displays the kernel release.
  • -v or --kernel-version: Shows the kernel version.
  • -m or --machine: Displays the machine hardware name.
  • -p or --processor: Shows the processor type.
  • -i or --hardware-platform: Displays the hardware platform.
  • -o or --operating-system: Shows the operating system name.

Man page link: uname

13. vmstat: Virtual Memory Statistics

The vmstat command displays information about system resources, including CPU activity, block IO, memory, paging, and traps. You can use vmstat command to get a snapshot for system performance and use it to monitor trends over time.

The basic syntax for the uname command is:

vmstat [options]

Run the command vmstat by itself to get information on all available monitoring metrics.

user@d1:~$ vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0  20868 167776  34028 1255864    0    1   101    43  183  365  1  1 98  0  0

To understand the reported values, use the table below.

ModeGroupValues
Vm ModeCPUThese are percentages of total CPU time.

us: Time spent running non-kernel code. (user time, including nice time)
sy: Time spent running kernel code. (system time)
id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.
IObi: Blocks received from a block device (blocks/s).
bo: Blocks sent to a block device (blocks/s).
Memoryswpd: the amount of virtual memory used.
free: the amount of idle memory.
buff: the amount of memory used as buffers.
cache: the amount of memory used as cache.
inact: the amount of inactive memory. (-a option)
active: the amount of active memory. (-a option)
Procsr: The number of processes waiting for run time.
b: The number of processes in uninterruptible sleep.
Systemin: The number of interrupts per second, including the clock. cs: The number of context switches per second.
Swapsi: Amount of memory swapped in from disk (/s).
so: Amount of memory swapped to disk (/s).
Disk ModeIOcur: I/O in progress
s: seconds spent for I/O
Readstotal: Total reads completed successfully
merged: grouped reads (resulting in one I/O)
sectors: Sectors read successfully ms: milliseconds spent reading
Writestotal: Total writes completed successfully
merged: grouped writes (resulting in one I/O)
sectors: Sectors written successfully ms: milliseconds spent writing

Man page link: vmstat

Summary

The commands shown above provide multiple ways to read Linux system metrics using command line tools. These commands provide invaluable insights into your system’s components, storage devices, memory, and processes.

Although there is overlap in the informatption provided by these commands, you should try them all to figure out which is best fit for you particular use case.

If you liked this list then also check post on 10 Useful Commands to Get CPU Information and Detailed Metrics Linux.