12 Commands to Check Linux System and Hardware Information: Best Guide

Posted on

12 Commands to Check Linux System and Hardware Information: Best Guide

12 Commands to Check Linux System and Hardware Information: Best Guide

In this guide, you will learn to use 12 Commands to Check Linux System and Hardware Information. As a Linux user, it’s crucial to understand your system’s capabilities and hardware configuration. This knowledge allows for efficient troubleshooting, informed resource allocation, and better system optimization. Here, the following Linux commands will provide detailed insights into your Linux system and its hardware components. Follow along with this article to familiarize yourself with these 12 Commands to Check Linux System and Hardware Information.

You can easily use Linux commands to check system information, CPU details, memory usage, hardware specifications, and more. Let’s explore these powerful commands and their usage in detail.

Step 1 – Check Linux System Information

Finding basic system information like the system name and kernel version is straightforward. The uname command is your friend here.

Command Number 1: The uname command

uname -a

The -a option displays all available system information.

**Example Output**
Linux ubuntu.jammy 5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

The output reveals your Linux system’s name, network hostname, kernel release, kernel version, and hardware architecture.

You can also use specific options with uname for targeted information:

  • uname -s: Prints the kernel name.
  • uname -n: Prints the network node hostname.
  • uname -r: Prints the kernel release.
  • uname -v: Prints the kernel version.
  • uname -m: Prints the machine hardware name.

Step 2 – Check Linux File System Partitions

Understanding your file system partitions is vital for disk space management and troubleshooting. The fdisk command helps you with this.

Command Number 2: The fdisk Command

Use the -l option with fdisk to list file system partitions:

fdisk -l
**Example Output**
Disk /dev/loop0: 61.96 MiB, 64970752 bytes, 126896 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/loop1: 61.89 MiB, 64901120 bytes, 126760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
...

Step 3 – Check Linux Hardware Information

For detailed hardware information, including motherboard details, RAM configuration, cache specifications, firmware version, bus speed, and CPU characteristics, the lshw command is invaluable.

Command Number 3: The lshw command

lshw

This command generates a comprehensive report of all hardware components. For a more concise overview, use the -short option:

lshw -short

Step 4 – Check Linux Memory, BIOS, and Processor Information

To retrieve specific information about your system’s memory, BIOS, and processor, utilize the dmidecode command.

Command number 4: The dmidecode command

dmidecode -t target-info

The -t option specifies the type of information you want to retrieve. Some common targets include:

  • bios: BIOS information.
  • system: System information.
  • baseboard: Baseboard (motherboard) information.
  • memory: Memory information.
  • processor: Processor information.

There are more commands to help you inspect the system for free space and used memory.

Command Number 5: The free Command

The free command, combined with the -m option, displays total, used, and free memory in megabytes.

free -m

Command Number 6: The df command

To check file system partitions, mount points, and disk space usage, use the df command with the -H option (which presents sizes in human-readable format).

df -H

Step 5 – Check Linux CPU Information

For detailed CPU information, the lscpu command provides a wealth of data.

Command Number 7: The lscpu command

lscpu
**Example Output**
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         46 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  2
  On-line CPU(s) list:   0,1
Vendor ID:               GenuineIntel
...

Step 6 – Check Linux USB Controllers

To inspect the USB devices connected to your computer, the lsusb command is essential.

Command Number 8: The lsusb command

lsusb

For more detailed information, use the -v option:

lsusb -v

Step 7 – Display SATA (Serial Advanced Technology Attached) Disk Information

SATA is a standard interface for connecting storage devices to the motherboard. To retrieve SATA disk information, such as serial number and model, use the hdparm command.

Command Number 9: The hdparm command

You must specify the device path:

hdparm <device name>

For example:

hdparm /dev/sda

Step 8 – Display Linux SCSI Devices

SCSI (Small Computer System Interface) is a high-level driver for managing various storage hardware. To check your Linux SCSI device information, use the lsscsi command.

Command Number 10: The lsscsi command

lsscsi

The -s option shows device sizes.

Note: The lsscsi command might not be installed by default.

To install it on Debian-based distributions:

apt install lsscsi

To install it on CentOS and RHEL-based distributions:

yum install lsscsi #centos7,rhel7
dnf install lsscsi #centos8,rhel8,rhel9

Step 9 – List Linux Block Devices

Block devices are storage devices (hard drives, flash drives, CD-ROMs) that can be accessed remotely. To list them, use the lsblk command.

Command Number 11: The lsblk command

lsblk
**Example Output**
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0    7:0    0    62M  1 loop /snap/core20/1587
loop1    7:1    0  61.9M  1 loop /snap/core20/1405
loop2    7:2    0  79.9M  1 loop /snap/lxd/22923
loop3    7:3    0  44.7M  1 loop /snap/snapd/15534
loop4    7:4    0    47M  1 loop /snap/snapd/16292
...

Step 10 – List Linux PCI devices

PCI (Peripheral Component Interconnect) connects various peripherals to the Linux platform. To list PCI devices, use the lspci command.

Command Number 12: The lspci command

lspci

Use the -v option for detailed information:

lspci -v

Conclusion

You should now be familiar with 12 Commands to Check Linux System and Hardware Information. These commands are essential tools for any Linux user to understand and manage their system effectively. Knowing how to check system information and hardware details is invaluable for troubleshooting, performance optimization, and general system administration. 12 Commands to Check Linux System and Hardware Information give you a solid foundation for understanding your system.

Do you know other Linux commands that are useful for system checks and hardware info? Please share your ideas in the comments!

Here are some other articles you might enjoy:

Best Sites to Run Linux in Browser

4 Ways To Install OpenCV on Debian 12 Bookworm

Clean Up Unnecessary and Junk Files on Ubuntu

Alternative Solutions for Gathering System and Hardware Information

While the provided commands are excellent, there are alternative approaches for collecting system and hardware data in Linux. Here are two different ways:

1. Using /proc Filesystem

The /proc filesystem is a virtual filesystem that provides an interface to kernel data structures. It contains various files that expose information about the system’s processes, hardware, and configuration.

  • Explanation: Instead of relying on specific commands, you can directly read relevant files within the /proc directory. This approach offers a more granular and sometimes more detailed view of the system’s internal state. The data in /proc is dynamically generated by the kernel, reflecting the current system status.

  • Code Example:

    To get CPU information, you can read the /proc/cpuinfo file:

    cat /proc/cpuinfo

    This will display detailed information about each CPU core, similar to the output of lscpu, but in a raw text format. You can then use tools like grep or awk to extract specific details. For example, to get the CPU model name:

    cat /proc/cpuinfo | grep "model name" | head -n 1

    To get memory information, you can read the /proc/meminfo file:

    cat /proc/meminfo

    This shows total memory, free memory, and other memory-related statistics.

    To find kernel version information, you can read the /proc/version file:

    cat /proc/version

    This shows the kernel version string.

  • Advantages: Direct access to kernel data, potentially more detailed information, no need for external commands.

  • Disadvantages: Requires understanding the structure and meaning of data within /proc files, data might be less formatted than command output, requires text processing to extract relevant information.

2. Using Python with psutil Library

Python provides a powerful and flexible way to access system information using the psutil (process and system utilities) library.

  • Explanation: psutil is a cross-platform library that provides a convenient interface for retrieving information about running processes and system utilization (CPU, memory, disks, network, sensors) in a portable way. It abstracts away the underlying operating system-specific mechanisms, making it easier to write system monitoring and management scripts.

  • Code Example:

    First, you need to install the psutil library:

    pip install psutil

    Then, you can use the following Python script to get system and hardware information:

    import psutil
    import platform
    
    # System Information
    print("System Information:")
    print(f"  Operating System: {platform.system()}")
    print(f"  Platform: {platform.platform()}")
    print(f"  Architecture: {platform.machine()}")
    
    # CPU Information
    print("nCPU Information:")
    print(f"  Physical Cores: {psutil.cpu_count(logical=False)}")
    print(f"  Total Cores: {psutil.cpu_count(logical=True)}")
    cpu_freq = psutil.cpu_freq()
    print(f"  Max Frequency: {cpu_freq.max:.2f} Mhz")
    print(f"  Current Frequency: {cpu_freq.current:.2f} Mhz")
    
    # Memory Information
    print("nMemory Information:")
    vm = psutil.virtual_memory()
    print(f"  Total Memory: {vm.total / (1024**3):.2f} GB")
    print(f"  Available Memory: {vm.available / (1024**3):.2f} GB")
    print(f"  Used Memory: {vm.used / (1024**3):.2f} GB")
    
    # Disk Information
    print("nDisk Information:")
    partitions = psutil.disk_partitions()
    for partition in partitions:
        print(f"  Device: {partition.device}")
        print(f"    Mount Point: {partition.mountpoint}")
        try:
            disk_usage = psutil.disk_usage(partition.mountpoint)
            print(f"    Total Space: {disk_usage.total / (1024**3):.2f} GB")
            print(f"    Used Space: {disk_usage.used / (1024**3):.2f} GB")
            print(f"    Free Space: {disk_usage.free / (1024**3):.2f} GB")
        except PermissionError:
            print("    Permission denied to access disk usage.")
    
    # Network Information
    print("nNetwork Information:")
    interfaces = psutil.net_if_addrs()
    for interface_name, interface_addresses in interfaces.items():
        for address in interface_addresses:
            if str(address.family) == 'AddressFamily.AF_INET':
                print(f"  Interface: {interface_name}")
                print(f"    IP Address: {address.address}")
                print(f"    Netmask: {address.netmask}")
                print(f"    Broadcast IP: {address.broadcast}")
  • Advantages: Cross-platform compatibility, easy-to-use API, well-structured data, allows for programmatic access and manipulation of system information.

  • Disadvantages: Requires Python and the psutil library to be installed, might not provide as detailed hardware information as lshw.

These alternative solutions offer different ways to access and process system and hardware information in Linux, providing flexibility depending on your specific needs and programming preferences.

Leave a Reply

Your email address will not be published. Required fields are marked *