Collecting Commands to Retrieve Linux System and Hardware Information (Updated 2024)

 2014-09-09

 2024-10-30

 Linux

This article is the English version of the Japanese article titled ‘(2024年更新)Linuxのシステムやハードウェア情報を取得するコマンドを集めてみた’.

Hello. This time, we will be focusing on commands to obtain Linux system information. We will pick out commands (or rather, CUI operations) that are likely to be useful when obtaining information about system settings and hardware, based on our own personal opinion. Please note that configuration files and commands vary depending on the distro and version. (This article was revised in October 2014.)

Obtaining CUP information

First, if you want information quickly, try typing the following command.

lscpu

Example Outout

Architecture:             x86_64
  CPU op-mode(s):         32-bit, 64-bit
  Address sizes:          48 bits physical, 48 bits virtual
  Byte Order:             Little Endian
CPU(s):                   8
  On-line CPU(s) list:    0-7
Vendor ID:                AuthenticAMD
  Model name:             AMD FX-8370E Eight-Core Processor
    CPU family:           21
    Model:                2
    Thread(s) per core:   2
    Core(s) per socket:   4
    Socket(s):            1
    Stepping:             0
    Frequency boost:      enabled
    CPU(s) scaling MHz:   42%
    CPU max MHz:          3300.0000
    CPU min MHz:          1400.0000
    BogoMIPS:             6600.37
...

If you cannot use lscpu, you can also get CPU information with the following command. Please try it.

$ cat /proc/cpuinfo

Example Outout

processor	: 0
vendor_id	: AuthenticAMD
cpu family	: 21
model		: 2
model name	: AMD FX-8370E Eight-Core Processor
stepping	: 0
microcode	: 0x6000852
cpu MHz		: 1399.782
cache size	: 2048 KB
physical id	: 0
siblings	: 8
core id		: 0
cpu cores	: 4
apicid		: 16
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes

Get memory (RAM) information

To get memory information, try the lsmem command.

lsmem

Example Outout

RANGE                                 SIZE  STATE REMOVABLE  BLOCK
0x0000000000000000-0x00000000bfffffff   3G online       yes   0-23
0x0000000100000000-0x000000043fffffff  13G online       yes 32-135

Memory block size:       128M
Total online memory:      16G
Total offline memory:      0B

You can also get this information by printing the information in /proc/meminfo.

$ cat /proc/meminfo

Example Outout

MemTotal:       16259248 kB
MemFree:        10493912 kB
MemAvailable:   13171000 kB
Buffers:          115504 kB
Cached:          2927836 kB
SwapCached:            0 kB
Active:          4809124 kB
Inactive:         543844 kB
Active(anon):    2465604 kB
...

Get PCI device information

The lspci command is useful for getting hardware information.

lspci

Example Outout

00:00.0 Host bridge: Advanced Micro Devices, Inc. [AMD/ATI] RD9x0/RX980 Host Bridge (rev 02)
00:00.2 IOMMU: Advanced Micro Devices, Inc. [AMD/ATI] RD890S/RD990 I/O Memory Management Unit (IOMMU)
00:02.0 PCI bridge: Advanced Micro Devices, Inc. [AMD/ATI] RD890/RD9x0/RX980 PCI to PCI bridge (PCI Express GFX port 0)
00:04.0 PCI bridge: Advanced Micro Devices, Inc. [AMD/ATI] RD890/RD9x0/RX980 PCI to PCI bridge (PCI Express GPP Port 0)
00:06.0 PCI bridge: Advanced Micro Devices, Inc. [AMD/ATI] RD890/RD9x0/RX980 PCI to PCI bridge (PCI Express GPP Port 2)
00:11.0 SATA controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 SATA Controller [AHCI mode] (rev 40)
00:12.0 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB OHCI0 Controller
00:12.2 USB controller: Advanced Micro Devices, Inc. [AMD/ATI] SB7x0/SB8x0/SB9x0 USB EHCI Controller
...

To get information about a module, try the lsmod command.

lsmod

Example Outout

Module                  Size  Used by
rfcomm                102400  4
snd_seq_dummy          12288  0
snd_hrtimer            12288  1
xt_nat                 12288  6
xt_tcpudp              16384  10
veth                   40960  0
xt_conntrack           12288  2
xt_MASQUERADE          16384  4
nf_conntrack_netlink    61440  0
nfnetlink              20480  2 nf_conntrack_netlink
...

Get information about connected HDDs and other block devices

If you want to get information about block devices such as HDDs, SSDs, and USB memory, first try running lsblk.

lsblk

Example Outout

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 238.5G  0 disk 
├─sda1   8:1    0     1G  0 part /boot/efi
├─sda2   8:2    0   230G  0 part /var/lib/docker
│                                /
└─sda3   8:3    0   7.5G  0 part [SWAP]
sdb      8:16   0 931.5G  0 disk 
└─sdb1   8:17   0   300G  0 part /home
...

Get information about connected USB devices

To get information about USB devices, use the lsusb command.

lsusb

Example Outout

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 1e4e:0103 Cubeternet USB2.0 Camera
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 002: ID 0409:005a NEC Corp. HighSpeed Hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
...

Check the capacity of the drive

If you want to check the capacity of a mounted drive, use the df command. If you add the -h option, you can display it more clearly.

df -h

Example Outout

Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        7.8G     0  7.8G   0% /dev
tmpfs           7.8G  528K  7.8G   1% /dev/shm
tmpfs           7.8G  1.3M  7.8G   1% /run
/dev/sda2       226G   49G  165G  23% /
...

Get information about inodes

If you want to check information about inodes, such as checking the inode usage rate, you can do so by running the df command with the -i option.

df -i

Example Outout

Filesystem     Inodes IUsed IFree IUse% Mounted on
devtmpfs         2.0M   602  2.0M    1% /dev
tmpfs            2.0M    16  2.0M    1% /dev/shm
tmpfs            2.0M   915  2.0M    1% /run
/dev/sda2         15M  460K   14M    4% /

Check the keyboard layout setting in Xorg

setxkbmap

If the keyboard layout is not enabled even after you set it in the X-related settings, it may be that another configuration file is being loaded. To check the current status, try running the following command.

setxkbmap -print -verbose 10

Example Outout

Setting verbose level to 10
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Success.
Applied rules from evdev:
rules:      evdev
model:      jp106
layout:     jp
options:    terminate:ctrl_alt_bksp
Trying to build keymap using the following components:
keycodes:   evdev+aliases(qwerty)
types:      complete
compat:     complete+japan
symbols:    pc+jp+inet(evdev)+terminate(ctrl_alt_bksp)
geometry:   pc(jp106)
xkb_keymap {
	xkb_keycodes  { include "evdev+aliases(qwerty)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete+japan"	};
	xkb_symbols   { include "pc+jp+inet(evdev)+terminate(ctrl_alt_bksp)"	};
	xkb_geometry  { include "pc(jp106)"	};

xprop

Another way is to use the xprop command. Note that xprop is not installed by default in some distros.

xprop -root | grep XKB

Example Outout

_XKB_RULES_NAMES(STRING) = "evdev", "jp106", "jp", "", "terminate:ctrl_alt_bksp"

Get information about environment variables

View the list of registered environment variables

export -p | less

Example Outout

export QT_IM_MODULE=fcitx5
export SHELL=/bin/zsh
export -i10 SHLVL=2
export TERM=xterm-256color
export TILIX_ID=3fd81864-e004-4cf4-ab5f-4e7b0ccf2b00
export USER=kuro

Discovering Available Fonts

fc-list is useful for displaying a list of font caches. The output is generally very long, so I use less to pipe it to the command line.

fc-list | less

Example Outout

/usr/share/fonts/X11/100dpi/helvB18.pcf.gz: Helvetica:style=Bold
/usr/share/fonts/X11/75dpi/timB12.pcf.gz: Times:style=Bold
/usr/share/fonts/noto/NotoSerifMyanmar-ExtraCondensedMedium.ttf: Noto Serif Myanmar ExtraCondensed,Noto Serif Myanmar ExtraCondensed Medium:style=Medium,Regular
/usr/share/fonts/SIL/Scheherazade-Regular.ttf: Scheherazade:style=Regular
/usr/share/fonts/noto/NotoSansEthiopic-ExtraLight.ttf: Noto Sans Ethiopic,Noto Sans Ethiopic ExtraLight:style=ExtraLight,Regular
/usr/share/fonts/noto/NotoSerif-Bold.ttf: Noto Serif,Noto Serif Bold:style=Bold,Regular

Check the keyboard layout settings for the console

The keyboard layout settings for the console will vary depending on the init or configuration tool you use.

In Debian (Ubuntu, Linux Mint, etc.), you can set the keyboard layout for the console screen and the Xorg server in a unified manner by installing console-setup. The keyboard configuration file is located in /etc/default/keyboard.

cat /etc/default/keyboad

If you use Systemd (Arch, etc.)

localectl status

Example Outout

System Locale: LANG=en_US.UTF-8
    VC Keymap: jp106
   X11 Layout: jp
    X11 Model: jp106
  X11 Options: terminate:ctrl_alt_bksp

The file that sets the key layout for the console screen is /etc/vconsole.conf, so you can also check by outputting this file.

cat /etc/vconsole.conf

If you are using Open RC (Gentoo, etc.)

If you are using OpenRC, the setting is in the OpenRC configuration file /etc/conf.d/keymaps.

cat /etc/conf.d/keymaps

See a list of services managed by the system

This is about the init system. There are various commands to view settings and information, but this time we will look at commands to get a list of each service. Since major distros have adopted Systemd, this article has been significantly revised from the original version posted in 2014.

Systemd(Fedora,Ubuntu,Arch Linux, etc)

In distributions that use Systemd for service management, use the systemctl command. You can see a list of services with the following command.

systemctl list-unit-files

Open RC(Gentoo linux, etc)

If you are using a distribution that uses OpenRC as init, you can use the rc-status command with the —service or -s option to check the status of all services.

rc-status -s

runit (Void Linux, etc)

In the case of runit, scripts under the /etc/sv/ directory are services that can be managed by runit. To manually activate a service, create a symbolic link under the /var/service directory.

To output a list of manageable services, use the following command.

ls -l /etc/sv

To see a list of currently active services use the following command:

ls -l /var/service

Distributions that use SysV-based init

SysV-based init was used in Debian and RedHat-based distributions in the past, but now many major distributions have switched to Systemd, and the situation is very different from when this post was written in 2014. The following content may contain outdated information. Thank you for your understanding.

For Debian-based systems, use the sysv-rc-conf command. It may not be included by default, so please look for it in the repository.

sysv-rc-conf --list

For RedHat systems, the chkconfig command can be used.

chkconfig --list

Summary

I have listed the commands I often use when I want to check the settings. While writing this article, I once again had mixed feelings about the current situation where the location of configuration files and commands differ for each distro and version. This complex current situation symbolizes the freedom and diversity of Linux, but at the same time, the tools and commands available to users change frequently, which strongly instills the impression that “it is a system where what you have learned cannot be put to good use.” Uniformity or diversity… Open source OS will continue to evolve while wavering between these two.