** 截取連續多個列內容 **linux
[root@linux01 ~]# awk -F: '{for(i=3;i<NF;i++) printf $i":";print $NF}' /etc/passwd -->經過循環解決多個列的選取 0:0:root:/root:/bin/bash 1:1:bin:/bin:/sbin/nologin 2:2:daemon:/sbin:/sbin/nologin 3:4:adm:/var/adm:/sbin/nologin 4:7:lp:/var/spool/lpd:/sbin/nologin 5:0:sync:/sbin:/bin/sync 6:0:shutdown:/sbin:/sbin/shutdown 7:0:halt:/sbin:/sbin/halt 8:12:mail:/var/spool/mail:/sbin/nologin 11:0:operator:/root:/sbin/nologin 12:100:games:/usr/games:/sbin/nologin 14:50:FTP User:/var/ftp:/sbin/nologin 99:99:Nobody:/:/sbin/nologin 999:997:systemd Bus Proxy:/:/sbin/nologin 192:192:systemd Network Management:/:/sbin/nologin 81:81:System message bus:/:/sbin/nologin 998:996:User for polkitd:/:/sbin/nologin 59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin 89:89::/var/spool/postfix:/sbin/nologin 74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin 997:995::/var/lib/chrony:/sbin/nologin 996:994:Jenkins Automation Server:/var/lib/jenkins:/bin/false 995:992::/var/opt/gitlab/nginx:/bin/false 994:991::/var/opt/gitlab:/bin/sh 993:990::/var/opt/gitlab/redis:/bin/false 992:989::/var/opt/gitlab/postgresql:/bin/sh 991:988::/var/opt/gitlab/prometheus:/bin/sh 1000:1000::/home/virftp:/sbin/nologin 72:72::/:/sbin/nologin
** 打印當前IP地址 **nginx
[root@linux01 ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.111.128 netmask 255.255.255.0 broadcast 192.168.111.255 inet6 fe80::9f24:73fe:b3f8:5c5c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:2d:de:67 txqueuelen 1000 (Ethernet) RX packets 65 bytes 7705 (7.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 85 bytes 9829 (9.5 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 1 (Local Loopback) RX packets 238 bytes 132906 (129.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 238 bytes 132906 (129.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@linux01 ~]# ifconfig|awk '/ens/{print $1;getline;print $2}'|xargs ens33: 192.168.111.128
** 把多個偶數行內容單行顯示 **git
[root@linux01 ~]# seq 11|sed -n 'n;p'|xargs -->單行顯示內容,沒有符號間隔 2 4 6 8 10 [root@linux01 ~]# seq 11|sed -n 'n;p'|sed ':a;N;s/\n/,/;ta' -->單行顯示內容,有符號間隔 2,4,6,8,10
** 查看鏈接某服務端口最多的的IP地址 **redis
[root@linux01 ~]# netstat -ntu|grep -w 8080|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr 4 127.0.0.1
** TCP各類狀態列表 **sql
[root@linux01 ~]# netstat -nt|grep -e 127.0.0.1 -e 0.0.0.0 -e ::: -v|grep tcp|awk '{print $6}'|sort|uniq -c|sort -nr 12 TIME_WAIT 2 ESTABLISHED
** 查看nginx進程數,若是接近預設值,說明不夠用,須要增長 **centos
[root@linux01 ~]# netstat -anpo|grep nginx|wc -l 6
** centos查看系統cpu個數、核心數、線程數 **bash
[root@linux01 ~]# grep "processor" /proc/cpuinfo|sort -u|wc -l -->線程數 1 [root@linux01 ~]# grep "physical id" /proc/cpuinfo|sort -u|wc -l -->CPU個數 1 [root@linux01 ~]# grep "core id" /proc/cpuinfo|sort -u|wc -l -->核心數 1
** 查看系統相關信息 **ssh
[root@linux01 ~]# grep MemTotal /proc/meminfo -->查看內存方法 MemTotal: 1867024 kB [root@linux01 ~]# cat /etc/redhat-release -->centos查看系統版本 CentOS Linux release 7.4.1708 (Core) [root@linux01 ~]# cat /proc/version -->查看centos內核的版本 Linux version 3.10.0-693.5.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Fri Oct 20 20:32:50 UTC 2017 [root@linux01 ~]# getconf LONG_BIT -->查看系統是64位仍是32位 64