Comprehensive Guide to Linux System Information Commands

Those who follow me are the kindest!

Only speaking for the people, using the pen to clarify the situation and measure the warmth of the world.

Did you know?

If you want to explore the secrets of Linux systems, here is a treasure trove of practical commands! From basic system information to hardware, disk, processes, network, and user information, all kinds of commands are included. For example, use <span>uname</span> to check the kernel version, and <span>top</span> for real-time process monitoring. Mastering them will allow you to easily gain insights into the system and embark on a journey of efficient management and troubleshooting!

01Comprehensive Guide to Linux System Information Commands

In Linux systems, there are many useful commands that can help us understand various information about the system. Below is a detailed introduction to these commands.

Basic System Information

uname

<span>uname</span> command can display basic information about the system, such as kernel name, hostname, kernel version, etc.

Common parameters:<span>-a</span>: Display all information.<span>-r</span>: Display kernel version.Example:

123456789# Display all information
uname -a
# Output example
Linux myhost 5.4.0-109-generic #123-Ubuntu SMP Fri Apr 8 16:08:38 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
# Display only kernel version
uname -r
# Output example
5.4.0-109-generic

hostname

<span>hostname</span>

The command is used to display or set the system’s hostname.

Example:

10111213141516# Display current hostname
hostname
# Output example
myhost
# Set hostname (requires root privileges)
sudo hostname newhost

lsb_release

<span>lsb_release</span> command can display information about the Linux distribution.

Common parameters:<span>-a</span>: Display all information.Example:

17181920212223
lsb_release -a
# Output example
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal

Hardware Information

lshw

<span>lshw</span> command is used to display hardware information of the system, including CPU, memory, disk, etc.

Common parameters:<span>-short</span>: Display information in a short format.Example:

24252627282930313233343536# Display all hardware information (requires root privileges)
sudo lshw
# Display information in short format
sudo lshw -short
# Output example
H/W path Device Class Description
=====================================================/0 system Computer
/0/0 bus Motherboard
/0/0/0 memory 64KiB BIOS
/0/0/100 bridge 4thGenCoreProcessor DRAM Controller
/0/0/100/1 bridge Xeon E3-1200 v3/4thGenCoreProcessor PCI Express x16 Controller
/0/0/100/1/0 display GK107 [GeForce GT 640]

lscpu

<span>lscpu</span> command is used to display information related to the CPU.

Example:以下视频来源于熊小白玩数码

37383940414243444546474849505152535455565758596061
lscpu
# Output example
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
ByteOrder: Little Endian
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: 60
Model name: Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz
Stepping: 3
CPU MHz: 2394.000
BogoMIPS: 5184.00
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
NUMA node0 CPU(s): 0-3

lsblk

<span>lsblk</span> command is used to list block device information, such as hard drives, USB drives, etc.

Example:

62636465666768697071
lsblk
# Output example
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 238.5G  0 disk
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0     1K  0 part
└─sda5   8:5    0 237.9G  0 part  ├─vgubuntu-root 252:0    0 230.9G  0 lvm  /
└─vgubuntu-swap_1 252:1    0     7G  0 lvm  [SWAP]
sr0     11:0    1  1024M  0 rom

free

<span>free</span> command is used to display memory usage of the system.

Common parameters:<span>-h</span>: Display information in a human-readable format.Example:

72737475767778798081828384# Display memory usage
free
# Output example
              total        used        free      shared  buff/cache   available
Mem:       8165920     2248340     4787700       75020     1129880     5477440
Swap:      7340028           0     7340028
# Display in human-readable format
free -h
# Output example
              total        used        free      shared  buff/cache   available
Mem:           7.8G        2.2G        4.6G         73M        1.1G        5.2G
Swap:          7.0G          0B        7.0G

Disk Usage Information

df

<span>df</span> command is used to display disk usage of the file system.

Common parameters:<span>-h</span>: Display information in a human-readable format.Example:

858687888990919293949596979899100101102103104105106107108109# Display disk usage
df
# Output example
Filesystem     1K-blocks     Used Available Use% Mounted on
udev             4031000        0   4031000   0% /dev
tmpfs             816592     8472    808120   2% /run
/dev/mapper/vgubuntu-root 242087936 15573880 214328840   7% /
tmpfs            4082944     2500   4080444   1% /dev/shm
tmpfs               5120        4      5116   1% /run/lock
tmpfs            4082944        0   4082944   0% /sys/fs/cgroup
/dev/sda1         523248    67208    456040  13% /boot/efi
tmpfs             816592       40    816552   1% /run/user/1000
# Display in human-readable format
df -h
# Output example
Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           798M  8.3M  790M   2% /run
/dev/mapper/vgubuntu-root  231G   15G  205G   7% /tmpfs           3.9G  2.5M  3.9G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1       512M   66M  447M  13% /boot/efi
tmpfs           798M   40K  798M   1% /run/user/1000

du

<span>du</span> command is used to estimate the disk usage of files or directories.

Common parameters:<span>-h</span>: Display information in a human-readable format.<span>-s</span>: Display only the total.Example:

110111112113114115116117118119120121# Display disk usage of each subdirectory in the current directory
du
# Display in human-readable format
du -h
# Display total of the current directory
du -s
# Display total in human-readable format
du -sh
# Output example
4.0K    ./test
8.0K    ./data
12K     .

Process Information

ps

<span>ps</span> command is used to display the current status of processes.

Common parameters:<span>-e</span>: Display all processes.<span>-f</span>: Display process information in full format.Example:

122123124125126127128129130131132133134135# Display current user's processes
ps
# Output example
  PID TTY          TIME CMD
 1234 pts/0    00:00:00 bash
 1235 pts/0    00:00:00 ps
# Display full information of all processes
ps -ef
# Output example
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 00:00:00 /sbin/init splash
root         2     0  0 00:00:00 [kthreadd]
root         3     2  0 00:00:00 [rcu_gp]

top

<span>top</span> command is a dynamic tool for displaying real-time system process information.

Example:

136top

After running the <span>top</span> command, you will enter an interactive interface that displays real-time information about the system, including CPU and memory usage, as well as detailed information about each process. You can sort and filter by pressing different keys. Press the <span>q</span> key to exit the <span>top</span> interface.

htop

<span>htop</span> is a more powerful and intuitive process monitoring tool than <span>top</span>. You need to install the <span>htop</span> package first (the installation method varies by system; for example, on Ubuntu, you can use <span>sudo apt install htop</span> to install).

Example:

137htop

<span>htop</span> has a more beautiful interface, clearer information display, and can also monitor system process information in real-time, with mouse operation support.

Network Information

ifconfig

<span>ifconfig</span> command is used to display or configure network interface information.

Example:

138139140141142143144145146147148149150151152153154155156ifconfig
# Output exampleeth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500        inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255        inet6 fe80::a00:27ff:fe12:3456  prefixlen 64  scopeid 0x20<link>        ether 08:00:27:12:34:56  txqueuelen 1000  (Ethernet)        RX packets 1000  bytes 123456 (123.4 KB)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 500  bytes 67890 (67.9 KB)        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536        inet 127.0.0.1  netmask 255.0.0.0        inet6 ::1  prefixlen 128  scopeid 0x10<host>        loop  txqueuelen 1000  (Local Loopback)        RX packets 10  bytes 1200 (1.2 KB)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 10  bytes 1200 (1.2 KB)        TX errors 0  dropped 0  overruns 0  carrier 0  collisions 0

ip

<span>ip</span> command is a more powerful alternative to <span>ifconfig</span>.

Example:

157158159160161162163164165166167168169170171# Display all network interface information
ip addr show
# Output example
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00    inet 127.0.0.1/8 scope host lo       valid_lft forever preferred_lft forever    inet6 ::1/128 scope host       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000    link/ether 08:00:27:12:34:56 brd ff:ff:ff:ff:ff:ff    inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic eth0       valid_lft 86399sec preferred_lft 86399sec    inet6 fe80::a00:27ff:fe12:3456/64 scope link       valid_lft forever preferred_lft forever

netstat

<span>netstat</span> command is used to display network connections, routing tables, network interface statistics, etc.

Common parameters:<span>-t</span>: Display TCP connections.<span>-u</span>: Display UDP connections.<span>-n</span>: Display addresses and port numbers in numeric form.<span>-l</span>: Display listening connections.Example:

172173174175176177178# Display all TCP listening connections
netstat -tnl
# Output example
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN

User Information

who

<span>who</span> command is used to display information about users currently logged into the system.

Example:

179180181182who
# Output example
user1    pts/0        2023-09-10 10:00 (192.168.1.101)
user2    pts/1        2023-09-10 10:30 (192.168.1.102)

w

<span>w</span> command is used to display information about users currently logged into the system, as well as what they are doing.

Example:

183184185186187188w
# Output example
 10:45:00 up  1:45,  2 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
user1    pts/0    192.168.1.101    10:00    0.00s  0.05s  0.00s w
user2    pts/1    192.168.1.102    10:30    0.00s  0.00s  0.00s bash

id

<span>id</span> command is used to display user identity information, including user ID, group ID, etc.

Example:

189190191id
# Output example
uid=1000(user1) gid=1000(user1) groups=1000(user1),4(adm),24(cdrom),27(sudo),46(plugdev),116(lpadmin),126(sambashare)

These are the commonly used information commands in Linux systems, which allow for a comprehensive understanding of various system information,

facilitating system management and troubleshooting.

Leave a Comment