zl程序教程

您现在的位置是:首页 >  系统

当前栏目

linux系统信息的查看

Linux系统 查看 信息
2023-06-13 09:18:23 时间

在 Linux 系统中,了解系统信息和管理系统是非常重要的。这可以帮助您监视系统状态、优化系统性能并保护系统安全。本文将介绍如何在 Linux 系统中查看和管理系统信息,并给出一些常见的示例。

一、查看系统信息

uname 命令

uname 命令可以用于查看系统信息,如内核版本、系统架构等。

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

lsb_release 命令

lsb_release 命令可以用于查看 Linux 发行版的信息。

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal

cat /etc/os-release 命令

cat /etc/os-release 命令可以用于查看 Linux 发行版的信息。

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

df 命令

df 命令可以用于查看磁盘空间使用情况。

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.8G     0  7.8G   0% /dev
tmpfs           1.6G  1.5M  1.6G   1% /run
/dev/sda1        70G  8.7G   58G  14% /
tmpfs           7.9G     0  7.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/sda6       197G   56G  132G  30% /home

free 命令

free 命令可以用于查看系统内存使用情况。

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           15Gi       2.2Gi        12Gi       516Mi       878Mi        12Gi
Swap:         2.0Gi          0B       2.0Gi

top 命令

top 命令可以用于实时查看系统的进程信息和系统资源占用情况。

top - 17:20:43 up  3:08,  2 users,  load average: 0.01, 0.02, 0.00
Tasks: 314 total,   1 running, 313 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.1 sy,  0.0 ni, 99.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  15894.5 total,  11912.6 free,   2265.6 used,    716.3 buff/cache
MiB Swap:   2048.0 total,   2048.0 free,      0.0 used.  12933.3 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S %CPU  %MEM     TIME+ COMMAND                                                                             
 1278 root      20   0  246024  39616  25484 S  0.3   0.2   4:00.90 Xorg                                                                                
 2902 user1     20   0 4729376 698180  81252 S  0.3   4.3   0:25.79 firefox                                                                             
 3113 user1     20   0 1730680 313860 110832 S  0.3   1.9   0:18.81 gnome-shell                                                                         
 3185 user1     20   0  787772 106440  69904 S  0.3   0.7   0:05.45 gnome-terminal-                                                                     
    1 root      20   0  169296  11440   7420 S  0.0   0.1   0:03.69 systemd                                                                             
    2 root      20   0       0      0      0 S  0.0   0.0   0:00.00 kthreadd                                                                            
    3 root       0 -20       0      0      0 I  0.0   0.0   0:00.00 rcu_gp                                                                              
    4 root       0 -20       0      0      0 I  0.0   0.0   0:00.00 rcu_par_gp                                                                          
    5 root       0 -20       0      0      0 I  0.0   0.0   0:00.00 kworker/0:0H-kblockd                                                                

ps 命令

ps 命令可以用于查看当前系统中的进程信息。

$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1 169296 11440 ?        Ss   10:06   0:03 /sbin/init
root         2  0.0  0.0      0     0 ?        S    10:06   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        I<   10:06   0:00 [rcu_gp]
root         4  0.0  0.0      0     0 ?        I<   10:06   0:00 [rcu_par_gp]
root         5  0.0  0.0      0     0 ?        I    10:06   0:00 [kworker/0:0H-kblockd]
root         6  0.0  0.0      0     0 ?        I<   10:06   0:00 [mm_percpu_wq]
root         7  0.0  0.0      0     0 ?        S    10:06   0:00 [ksoftirqd/0]
root         8  0.0  0.0      0     0 ?        I    10:06   0:00 [rcu_sched]
root         9  0.0  0.0      0     0 ?        S    10:06   0:00 [migration/0]
root        10  0.0  0.0      0     0 ?        S    10:06   0:00 [watchdog/0]
root        11  0.0  0.0      0     0 ?        S    10:06   0:00 [cpuhp/0]
root        12  0.0  0.0      0     0 ?        S    10:06   0:00 [cpuhp/1]
root        13  0.0  0.0      0     0 ?        S    10:06   0:00 [watchdog/1]
root        14  0.0  0.0      0     0 ?        S    10:06   0:00 [migration/1]
root        15  0.0  0.0      0     0 ?        S    10:06   0:00 [ksoftirqd/1]

lsof 命令

lsof 命令可以用于查看当前系统中打开的文件和网络连接等信息。

$ sudo lsof -iTCP -sTCP:LISTEN
COMMAND   PID        USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sshd      898        root    3u  IPv4  18387      0t0  TCP *:ssh (LISTEN)
sshd      898        root    4u  IPv6  18389      0t0  TCP *:ssh (LISTEN)
dockerd  1058        root   13u  IPv6  19048      0t0  TCP *:2376 (LISTEN)
dockerd  1058        root   16u  IPv4  19114      0t0  TCP *:2376 (LISTEN)
master   1092        root   13u  IPv4  19186      0t0  TCP localhost:smtp (LISTEN)
master   1092        root   14u  IPv6  19187      0t0  TCP localhost:smtp (LISTEN)