系统状态检测命令
1、ifconfig
ifconfig 命令用于获取网卡配置与网络状态等信息,格式为“ifconfig [网络设备] [参数]”
使用 ifconfig 命令来查看本机当前的网卡配置与网络状态等信息时,其实主要查看的就是网卡名称、inet 参数后面的 IP 地址、ether 参数后面的网卡物理地址(又称为 MAC 地址),以及 RX、TX 的接收数据包与发送数据包的个数及累计流量
[root@hecs-169544 logsaas]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.199 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::f816:3eff:fe61:d59d prefixlen 64 scopeid 0x20<link>
ether fa:16:3e:61:d5:9d txqueuelen 1000 (Ethernet)
RX packets 5289490 bytes 2074226923 (1.9 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5238260 bytes 343517695 (327.6 MiB)
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 285 bytes 406313 (396.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 285 bytes 406313 (396.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、uname
uname 命令用于查看系统内核与系统版本等信息,格式为“uname [-a]”
在使用 uname 命令时,一般会固定搭配上-a 参数来完整地查看当前系统的内核名称、主机名、内核发行版本、节点名、系统时间、硬件名称、硬件平台、处理器类型以及操作系统名称等信息。
[root@hecs-169544 logsaas]# uname -a
Linux hecs-169544 3.10.0-1160.15.2.el7.x86_64 #1 SMP Wed Feb 3 15:06:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
3、uptime
uptime 用于查看系统的负载信息,格式为 uptime
uptime 命令可以显示当前系统时间、系统已运行时间、启用终端数量以及平均负载值等信息。平均负载值指的是系统在最近 1 分钟、5 分钟、15 分钟内的压力情况;负载值越低越好,尽量不要长期超过 1,在生产环境中不要超过 5
[root@hecs-169544 logsaas]# uptime
16:19:28 up 27 days, 25 min, 1 user, load average: 0.86, 0.78, 0.39
4、free
free 用于显示当前系统中内存的使用量信息,格式为“free [-h]”
[root@hecs-169544 logsaas]# free -h
内存总量 已用量 空闲量 进程共享量 磁盘缓存量 可用量
total used free shared buff/cache available
Mem: 1.8G 349M 406M 24M 1.1G 1.0G
Swap: 0B 0B 0B
5、who
who 用于查看当前登入主机的用户终端信息,格式为“who [参数]”
[root@hecs-169544 logsaas]# who
root pts/0 2022-03-09 14:15 (183.129.241.197)
6、last
last 命令用于查看所有系统的登录记录,格式为“last [参数]”
-n 展示前 num 个
[root@hecs-169544 logsaas]# last -n 5
root pts/0 183.129.241.197 Wed Mar 9 14:15 still logged in
root pts/0 183.129.241.196 Thu Feb 17 13:17 - 19:20 (06:03)
root pts/1 183.129.241.196 Wed Feb 16 17:14 - 21:44 (04:29)
root pts/0 183.129.241.196 Wed Feb 16 17:08 - 21:43 (04:35)
root pts/1 183.129.241.196 Thu Feb 10 15:57 - 20:09 (04:12)
-R 省略 hostname 的列
[root@hecs-169544 logsaas]# last -n 5 -R
root pts/0 Wed Mar 9 14:15 still logged in
root pts/0 Thu Feb 17 13:17 - 19:20 (06:03)
root pts/1 Wed Feb 16 17:14 - 21:44 (04:29)
root pts/0 Wed Feb 16 17:08 - 21:43 (04:35)
root pts/1 Thu Feb 10 15:57 - 20:09 (04:12)
7、history
history 命令用于显示历史执行过的命令,格式为“history [-c]”
执行 history 命令能显示出当前用户在本地计算机中执行过的最近 1000 条命令记录。如果觉得 1000 不够用,还可以自定义/etc/profile 文件中的HISTSIZE 变量值。在使用 history 命令时,如果使用-c 参数则会清空所有的命令历史记录。
[root@hecs-169544 logsaas]# history
1 2022-02-10 15:57:42 root cd /usr/local/software/
2 2022-02-10 15:57:43 root ll
3 2022-02-10 16:05:48 root rpm -qa|grep java
4 2022-02-10 16:05:54 root rpm -qa|grep jdk
5 2022-02-10 16:05:59 root rpm -qa|grep gcj
还可以使用“!编码数字”的方式来重复执行某一次的命令
301 2022-03-09 16:36:42 root clear
302 2022-03-09 16:36:48 root history
[root@hecs-169544 logsaas]# !301
clear