Linux Centos6.x 下常用查询命令整理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux Centos6.x 下常用查询命令整理相关的知识,希望对你有一定的参考价值。
Linux Centos6.x 下常用查询命令整理
---- 1.系统基本信息 ----
查看 系统版本
cat /etc/redhat-release
[[email protected] ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
查看 处理器架构
arch 或 uname -m
[[email protected] ~]# arch
x86_64
[[email protected] ~]# uname -m
x86_64
查看 内核版本
uname -r 或 cat /proc/version
[[email protected] ~]# uname -r
2.6.32-696.23.1.el6.x86_64
[[email protected] ~]# cat /proc/version
Linux version 2.6.32-696.23.1.el6.x86_64 ([email protected]) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Tue Mar 13 22:44:18 UTC 2018
查看 系统信息
uname -a
[[email protected] ~]# uname -a
Linux test 2.6.32-696.23.1.el6.x86_64 #1 SMP Tue Mar 13 22:44:18 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
查看 系统时间
date
[[email protected] ~]# date
Thu Apr 5 16:06:07 CST 2018
---- 2. 用户相关信息 ----
查看 当前用户
whoami
[[email protected] ~]# whoami
root
查看 目前登录系统用户
w
[[email protected] ~]# w
15:50:09 up 22:04, 1 user, load average: 0.00, 0.00, 0.00
USER TTY FROM [email protected] IDLE JCPU PCPU WHAT
root pts/0 255.255.255.255 15:37 0.00s 0.00s 0.00s w
查看 用户信息
cat /etc/passwd
[[email protected] ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
查看 用户组信息
cat /etc/group
[[email protected] ~]# cat /etc/group
root:x:0:
bin:x:1:bin,daemon
---- 3. 硬件+性能相关 ----
查看 CPU信息
cat /proc/cpuinfo
[[email protected] ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 79
model name : Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz
......
查看 内存信息
cat /proc/meminfo
[[email protected] ~]# cat /proc/meminfo
MemTotal: 2054152 kB
MemFree: 1638884 kB
Buffers: 31096 kB
Cached: 302444 kB
SwapCached: 0 kB
......
查看 cpu 内存 每五秒更新
vmstat 5
[[email protected] ~]# vmstat 5
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 1638884 31112 302536 0 0 3 3 68 157 0 0 100 0 0
0 0 0 1638728 31112 302556 0 0 0 0 79 168 0 0 100 0 0
0 0 0 1638728 31120 302556 0 0 0 2 86 176 0 0 100 0 0
0 0 0 1638728 31120 302556 0 0 0 0 79 167 0 0 100 0 0
查看 磁盘剩余空间
df -h
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.6G 36G 5% /
tmpfs 939M 0 939M 0% /dev/shm
查看磁盘剩余Inodes节点
df -i
[[email protected] ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/vda1 2621440 62268 2559172 3% /
tmpfs 240257 1 240256 1% /dev/shm
查看 系统平均负载
cat /proc/loadavg
1、5、15分钟内的平均进程数、正在运行的进程数/进程总数、最近运行的进程ID号
[[email protected] ~]# cat /proc/loadavg
0.00 0.00 0.00 1/103 9728
查看 系统运行时间+负载
uptime
[[email protected] ~]# uptime
16:01:41 up 22:15, 1 user, load average: 0.00, 0.00, 0.00
网络状态查看
// 查看 指定端口
netstat -nlpt | grep 22
[[email protected] test]# netstat -nlpt | grep 22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1245/sshd
// 查看当前tcp连接数(ESTABLISHED)
netstat -nat | grep ESTABLISHED|wc -l
[[email protected] test]# netstat -nat | grep ESTABLISHED|wc -l
2
// 查看当前tcp连接数(TIME_WAIT)
netstat -na | grep ‘TIME_WAIT‘ |wc -l
[[email protected] test]# netstat -na | grep ‘TIME_WAIT‘ |wc -l
0
// 查看当前tcp连接数(指定端口)
netstat -nat | grep -i "22"|wc -l
[[email protected] test]# netstat -nat | grep -i "22"|wc -l
2
---- 4. 服务相关 ----
系统运行情况 - top
top
[[email protected] ~]# top
top - 16:11:31 up 22:25, 1 user, load average: 0.00, 0.00, 0.00
Tasks: 76 total, 1 running, 75 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.3%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 2054152k total, 417164k used, 1636988k free, 31384k buffers
Swap: 0k total, 0k used, 0k free, 303324k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1168 root 20 0 125m 12m 8588 S 0.0 0.6 2:31.16 AliYunDun
9677 root 20 0 100m 4464 3424 S 0.0 0.2 0:00.04 sshd
1364 postfix 20 0 81200 3516 2632 S 0.0 0.2 0:00.04 qmgr
系统运行情况 - htop
htop
需 yum install htop
[[email protected] ~]# htop
CPU[ 0.0%] Tasks: 25, 27 thr; 1 running
Mem[|||||##**************** 81/2006MB] Load average: 0.00 0.00 0.00
Swp[ 0/0MB] Uptime: 22:26:59
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command
1168 root 20 0 125M 12832 8588 S 0.3 0.6 2:31.33 /usr/local/aegis/aegis_client/aegis_10_41/AliYunDun
查看指定进程
ps -ef | grep 进程名
[[email protected] ~]# ps -ef | grep sshd
root 1245 1 0 Apr04 ? 00:00:00 /usr/sbin/sshd
root 9677 1245 0 15:37 ? 00:00:00 sshd: [email protected]/0
查看服务状态
chkconfig --list
[[email protected] ~]# chkconfig --list
aegis 0:off 1:off 2:on 3:on 4:on 5:on 6:off
agentwatch 0:off 1:off 2:on 3:on 4:on 5:on 6:off
aliyun-util 0:off 1:off 2:on 3:on 4:on 5:on 6:off
---- 5. 日志相关 ----
查看 当前用户执行过的命令
history
[[email protected] ~]# history
1 ls
2 clear
3 history
查看 最近5行系统日志
dmesg | tail -n5
[[email protected] ~]# dmesg | tail -n5
alloc irq_desc for 30 on node -1
alloc kstat_irqs on node -1
virtio-pci 0000:00:04.0: irq 30 for MSI/MSI-X
IPv6: Loaded, but administratively disabled, reboot required to enable
type=1305 audit(1522835175.952:3): audit_pid=1031 old=0 auid=4294967295 ses=4294967295 res=1
---- 6. 文件相关 ----
显示文件总大小 每个文件大小
ll -ht
[[email protected] test]# ll -ht
total 12K
-rw-r--r-- 1 root root 19 Apr 5 09:48 1.txt
-rw-r--r-- 1 root root 1 Apr 4 17:56 3.png
-rw-r--r-- 1 root root 1 Apr 4 17:56 2.png
tail 查看文件
// 显示最后20行
tail -n 20 error.log
// 时时刷新日志显示
tail -f access.log
全局查找文件
find / -name 1.txt
[[email protected] test]# find / -name 1.txt
/usr/local/src/test/1.txt
以上是关于Linux Centos6.x 下常用查询命令整理的主要内容,如果未能解决你的问题,请参考以下文章