1、ifconfig命令
ifconfig命令用於獲取網卡配置與網絡狀態等信息,格式為“ifconfig [網絡設備] [參數]”。
使用ifconfig命令來查看本機當前的網卡配置與網絡狀態等信息時,其實主要查看的就是網卡名稱、inet參數后面的IP地址、ether參數后面的網卡物理地址(又稱為MAC地址),以及RX、TX的接收數據包與發送數據包的個數及累計流量(即下面加粗的信息內容):
[root@linuxprobe ~]# ifconfig eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.111 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::20c:29ff:fec6:6e32 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:c6:6e:32 txqueuelen 1000 (Ethernet) RX packets 18358 bytes 20452042 (19.5 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 9241 bytes 640620 (625.6 KiB) 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 0 (Local Loopback) RX packets 1738 bytes 140816 (137.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1738 bytes 140816 (137.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、uname命令
uname命令用於查看系統內核與系統版本等信息,格式為“uname [-a]”。
在使用uname命令時,一般會固定搭配上-a參數來完整地查看當前系統的內核名稱、主機名、內核發行版本、節點名、系統時間、硬件名稱、硬件平台、處理器類型以及操作系統名稱等信息。
[root@linuxprobe ~]# uname -a Linux linuxprobe.com 3.10.0-123.el7.x86_64 #1 SMP Mon May 5 11:16:57 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
如果要查看當前系統版本的詳細信息,則需要查看redhat-release文件,其命令以及相應的結果如下:
[root@linuxprobe ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.0 (Maipo)
3、uptime命令
uptime用於查看系統的負載信息,格式為uptime。
uptime命令真的很棒,它可以顯示當前系統時間、系統已運行時間、啟用終端數量以及平均負載值等信息。
平均負載值指的是系統在最近1分鍾、5分鍾、15分鍾內的壓力情況(下面加粗的信息部分);負載值越低越好,盡量不要長期超過1,在生產環境中不要超過5。
[root@linuxprobe ~]# uptime 08:47:09 up 7:29, 3 users, load average: 0.03, 0.09, 0.09
4、free命令
free用於顯示當前系統中內存的使用量信息,格式為“free [-h]”。
為了保證Linux系統不會因資源耗盡而突然宕機,運維人員需要時刻關注內存的使用量。在使用free命令時,可以結合使用-h參數以更人性化的方式輸出當前內存的實時使用量信息。表1 所示為在我的電腦上執行free -h命令之后的輸出信息。需要注意的是,輸出信息中的中文注釋是作者自行添加的內容,實際輸出時沒有相應的參數解釋。
[root@linuxprobe ~]# free -h
表1 執行free -h命令后的輸出信息
|
內存總量 |
已用量 |
可用量 |
進程共享的內存量 |
磁盤緩存的內存量 |
緩存的 |
|
total |
used |
free |
shared |
buffers |
cached |
Mem |
1.8GB |
991MB |
835MB |
9.9MB |
928KB |
338MB |
-/+ buffers/cache |
|
651MB |
1.1G |
|
|
|
Swap |
2.0GB |
0 |
2.0GB |
|
|
|
5、who命令
who用於查看當前登入主機的用戶終端信息,格式為“who [參數]”。
這三個簡單的字母可以快速顯示出所有正在登錄本機的用戶的名稱以及他們正在開啟的終端信息。表2 所示為執行who命令后的結果。
[root@linuxprobe ~]# who
表2 執行who命令的結果
登錄的用戶名 |
終端設備 |
登錄到系統的時間 |
admin |
:0 |
2018-08-05 21:54 (:0) |
admin |
pts/0 |
2018-08-04 22:22 (:0) |
admin |
tty4 |
2018-08-04 22:19 |
6、last命令
last命令用於查看所有系統的登錄記錄,格式為“last [參數]”。
使用last命令可以查看本機的登錄記錄。但是,由於這些信息都是以日志文件的形式保存在系統中,因此黑客可以很容易地對內容進行篡改。千萬不要單純以該命令的輸出信息而判斷系統有無被惡意入侵!
[root@linuxprobe ~]# who admin :0 2018-08-04 21:54 (:0) admin pts/0 2018-08-04 22:22 (:0) admin tty4 2018-08-04 22:19 [root@linuxprobe ~]# last admin pts/0 :0 Sat Aug 4 22:22 still logged in admin tty4 Sat Aug 4 22:19 still logged in admin pts/0 :0 Sat Aug 4 22:11 - 22:19 (00:07) admin :0 :0 Sat Aug 4 21:54 still logged in (unknown :0 :0 Sat Aug 4 21:53 - 21:54 (00:00) reboot system boot 3.10.0-123.el7.x Sun Aug 5 05:45 - 08:58 (03:13) admin pts/0 :0 Sat Jul 28 09:38 - crash (7+20:06) admin tty4 Sat Jul 28 06:55 - crash (7+22:49) admin :0 :0 Sat Jul 28 06:54 - crash (7+22:50) (unknown :0 :0 Sat Jul 28 06:52 - 06:54 (00:02) reboot system boot 3.10.0-123.el7.x Sat Jul 28 14:44 - 08:58 (7+18:14)
..........................省略部門登錄信息..................................
reboot system boot 3.10.0-123.el7.x Thu Jul 26 18:03 - 08:58 (9+14:54) admin tty4 Wed Jul 25 09:35 - crash (1+08:28) admin :0 :0 Wed Jul 25 09:03 - crash (1+09:00) (unknown :0 :0 Wed Jul 25 08:59 - 09:03 (00:03) reboot system boot 3.10.0-123.el7.x Wed Jul 25 16:43 - 08:58 (10+16:15) wtmp begins Wed Jul 25 16:43:43 2018
7、history命令
history命令用於顯示歷史執行過的命令,格式為“history [-c]”。
執行history命令能顯示出當前用戶在本地計算機中執行過的最近1000條命令記錄。如果覺得1000不夠用,還可以自定義/etc/profile文件中的HISTSIZE變量值。在使用history命令時,如果使用-c參數則會清空所有的命令歷史記錄。還可以使用“!編碼數字”的方式來重復執行某一次的命令。總之,history命令有很多有趣的玩法等待您去開發。
[root@linuxprobe ~]# history 1 su admin 2 cd ~ 3 ehco Linuxprobe.com 4 echo Linuxprobe.com 5 echo $SHELL 6 cd /bin/bash/ 7 date 8 date "+%Y-%m-%d %H:%M:%S" 9 date "+%Y-%m-%d %I:%M:%S" 10 date -s "20180805 10:30:00" 11 date 12 date "+%j" 13 date 14 systemd --version 15 systemctl --version 16 ifconfig17 cat /etc/redhat-release18 top 19 pidof sshd 20 kill 1657 [root@linuxprobe ~]# !13 date Sun Aug 5 09:02:58 EDT 2018
歷史命令會被保存到用戶家目錄中的.bash_history文件中。Linux系統中以點(.)開頭的文件均代表隱藏文件,這些文件大多數為系統服務文件,可以用cat命令查看其文件內容。
[root@linuxprobe ~]# cat ~/.bash_history
要清空當前用戶在本機上執行的Linux命令歷史記錄信息,可執行如下命令:
[root@linuxprobe ~]# history -c
8、sosreport命令
sosreport命令用於收集系統配置及架構信息並輸出診斷文檔,格式為sosreport。
當Linux系統出現故障需要聯系技術支持人員時,大多數時候都要先使用這個命令來簡單收集系統的運行狀態和服務配置信息,以便讓技術支持人員能夠遠程解決一些小問題,亦或讓他們能提前了解某些復雜問題。在下面的輸出信息中,加粗的部分是收集好的資料壓縮文件以及校驗碼,將其發送給技術支持人員即可:
[root@linuxprobe ~]# sosreport sosreport (version 3.0) This command will collect diagnostic and configuration information from this Red Hat Enterprise Linux system and installed applications. An archive containing the collected information will be generated in /var/tmp and may be provided to a Red Hat support representative. Any information provided to Red Hat will be treated in accordance with the published support policies at: https://access.redhat.com/support/ The generated archive may contain data considered sensitive and its content should be reviewed by the originating organization before being passed to any third party. No changes will be made to system configuration. Press ENTER to continue, or CTRL-C to quit. 此處敲擊回車來確認收集信息 Please enter your first initial and last name [linuxprobe.com]:此處敲擊回車來確認主機編號 Please enter the case number that you are generating this report for:此處敲擊回車來確認主機編號 Running plugins. Please wait ... Running 70/70: yum... Creating compressed archive... Your sosreport has been generated and saved in: /var/tmp/sosreport-linuxprobe.com-20170905230631.tar.xz The checksum is: 79436cdf791327040efde48c452c6322 Please send this file to your support representative.