1. 程式人生 > >Linux Centos6.x 下常用查詢命令整理

Linux Centos6.x 下常用查詢命令整理

Linux Centos 命令 查詢

Linux Centos6.x 下常用查詢命令整理

---- 1.系統基本信息 ----

查看 系統版本

cat /etc/redhat-release

[root@test ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)

查看 處理器架構

arch 或 uname -m

[root@test ~]# arch
x86_64
[root@test ~]# uname -m
x86_64

查看 內核版本

uname -r 或 cat /proc/version

[root@test ~]# uname -r
2.6.32-696.23.1.el6.x86_64
[root@test ~]# 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

[root@test ~]# 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

[root@test ~]# date
Thu Apr  5 16:06:07 CST 2018

---- 2. 用戶相關信息 ----

查看 當前用戶

whoami

[root@test ~]# whoami
root

查看 目前登錄系統用戶

w

[root@test ~]# w
15:50:09 up 22:04,  1 user,  load average: 0.00, 0.00, 0.00
USER    TTY      FROM              LOGIN@  IDLE  JCPU  PCPU WHAT
root    pts/0    255.255.255.255  15:37    0.00s  0.00s  0.00s w

查看 用戶信息

cat /etc/passwd

[root@test ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin

查看 用戶組信息

cat /etc/group

[root@test ~]# cat /etc/group
root:x:0:
bin:x:1:bin,daemon

---- 3. 硬件+性能相關 ----

查看 CPU信息

cat /proc/cpuinfo

[root@test ~]# 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

[root@test ~]# cat /proc/meminfo
MemTotal:        2054152 kB
MemFree:        1638884 kB
Buffers:          31096 kB
Cached:          302444 kB
SwapCached:            0 kB
......

查看 cpu 內存 每五秒更新

vmstat 5

[root@test ~]# 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

[root@test ~]# 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

[root@test ~]# 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號

[root@test ~]# cat /proc/loadavg
0.00 0.00 0.00 1/103 9728

查看 系統運行時間+負載

uptime

[root@test ~]# uptime
16:01:41 up 22:15,  1 user,  load average: 0.00, 0.00, 0.00
網絡狀態查看
// 查看 指定端口
netstat -nlpt | grep 22

[root@test 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

[root@test test]# netstat -nat | grep ESTABLISHED|wc -l
2

// 查看當前tcp連接數(TIME_WAIT)
netstat -na  | grep ‘TIME_WAIT‘ |wc -l

[root@test test]# netstat -na  | grep ‘TIME_WAIT‘ |wc -l
0

//  查看當前tcp連接數(指定端口)
netstat -nat | grep -i "22"|wc -l

[root@test test]# netstat -nat | grep -i "22"|wc -l
2

---- 4. 服務相關 ----

系統運行情況 - top

top

[root@test ~]# 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

[root@test ~]# 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 進程名

[root@test ~]# 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: root@pts/0 

查看服務狀態

chkconfig --list

[root@test ~]# 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

[root@test ~]# history
    1  ls
    2  clear
    3  history
查看 最近5行系統日誌
dmesg | tail -n5

[root@test ~]# 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

[root@test 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

[root@test test]# find / -name 1.txt
/usr/local/src/test/1.txt

Linux Centos6.x 下常用查詢命令整理