1. 程式人生 > 實用技巧 >Linux就該這麼學28期——Day02 2.4-2.8

Linux就該這麼學28期——Day02 2.4-2.8

2.4 系統狀態檢測命令

ifconfig  查詢網絡卡配置和網路狀態等資訊  WIN系統——ipconfig  ifconfig = interface config

[root@linuxprobe ~]# ifconfig
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.10  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::c8f8:f5c5:8251:aeaa  prefixlen 64
scopeid 0x20 ether 00:0c:29:7d:27:bf txqueuelen 1000 (Ethernet) RX packets 304 bytes 33283 (32.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 91 bytes 11052 (10.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

不同版本中網絡卡的預設名稱如下:

RHEL 5/6  eth0  eth1

RHEL 7   eth16777728

RHEL 8   ens160

uname  檢視系統核心與系統版本等資訊

[root@localhost ~]# uname -a
Linux localhost.localdomain 4.18.0-80.el8.x86_64 #1 SMP Wed Mar 13 12:02:46 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Linux 核心名稱
localhost.localdomain  主機名
4.18.0-80.el8.x86_64  核心版本
#1 SMP Wed Mar 13 12:02:46 UTC 2019  系統打包時間
x86_64 x86_64 x86_64 硬體名稱  硬體平臺  處理器型別
GNU/Linux  OS名稱  GNU開源
檢視當前系統版本的詳細資訊
[root@localhost ~]# cat /etc/redhat-release Red Hat Enterprise Linux release 8.0 (Ootpa)

uptime  檢視CPU負載  所顯示的內容與top命令顯示的第一行一致

[root@localhost ~]# uptime
 12:36:37 up 18 min,  1 user,  load average: 0.01, 0.04, 0.07
當前時間  已執行時間  啟用終端數量        1分鐘  5分鐘  15分鐘
RHEL8中 GUI不算終端,只統計使用者的數量
負載值越低越好,建議是負載值保持在1左右,不要超過5就好

free  顯示記憶體當前使用量

-h    human-readable    以可讀性最高的形式輸出,更人性化  即易讀模式
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          1.9Gi       1.2Gi       158Mi        13Mi       573Mi       558Mi
Swap:         2.0Gi       3.0Mi       2.0Gi
[root@localhost ~]# free -g
              total        used        free      shared  buff/cache   available
Mem:              1           1           0           0           0           0
Swap:             1           0           1
[root@localhost ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1966        1234         158          13         573         558
Swap:          2047           3        2044

who  看哪個使用者登入著呢

[root@localhost ~]# who
root     tty2         2020-10-10 12:20 (tty2)
登陸的使用者名稱  終端裝置(遠端的會顯示IP)  登陸時間

last  用於調取登陸記錄,僅供參考

[root@localhost ~]# last
root     tty2         tty2             Sat Oct 10 12:20   still logged in
reboot   system boot  4.18.0-80.el8.x8 Sat Oct 10 12:17   still running
root     tty2         tty2             Sat Oct 10 15:50 - 17:24  (-22:26)
reboot   system boot  4.18.0-80.el8.x8 Sat Oct 10 15:50 - 17:24  (-22:25)
root     tty2         tty2             Mon Oct  5 03:59 - down   (18:26)
reboot   system boot  4.18.0-80.el8.x8 Mon Oct  5 03:35 - 22:25  (18:50)
root     tty2         tty2             Sun Oct  4 00:32 - crash (1+03:03)
reboot   system boot  4.18.0-80.el8.x8 Sun Oct  4 00:21 - 22:25 (1+22:03)

wtmp begins Sun Oct  4 00:21:51 2020

history  顯示執行過的歷史命令  

[root@localhost ~]# history
    1  man echo
    2  date
    3  date "+%Y-%m-%d"
    4  date "+%Y-%m-%d %H-%M-%S"
    5  timedatectl set-time 21:20
    6  date
    7  echo Linuxprobe.com
可以使用 !編碼數字 的方式重複執行某一次的命令
[root@localhost ~]# !48
who
root     tty2         2020-10-10 12:20 (tty2)

歷史命令會被儲存到使用者家目錄中的.bash_history檔案中
[root@linuxprobe ~]# cat ~/.bash_history
history -c  清空當前使用者在本機上執行過的命令記錄

sosreport  收集系統配置及架構資訊並輸出診斷文件  可以理解為體檢報告

2.5 查詢定位檔案命令