列出当前打开的开放端口
# netstat -tulnp | awk '{print $4}' | grep ':[0-9]\+' -o | grep '[0-9]\+' -o
# netstat -tulnp | awk '{print $4}' | grep "[0-9]\+"| awk -F: '{print $2}'
获取IP地址
ifconfig ens192| egrep -o "inet [^ ]*"|grep -o "[0-9.]*"
查找文件夹下的文件并且做相关的操作
find . -name \*.sh -print0 | xargs -I{} -0 ls -l {}
字符串切片替换
# var='this is a line of text'
# echo ${var/line/replace}
this is a replace of text
# echo ${var:4}
is a line of text
# echo ${var:4:8}
is a li
获取文件夹下的文件大小并且排序
# du -ak /root | sort -nrk 1| head
5065704 /root
3821440 /root/software.tar.gz
626800 /root/mysql_5.7_install
626760 /root/mysql_5.7_install/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
617360 /root/mysql5.7.v2.tar.gz
20 /root/.mysql_history
12 /root/mysql_5.7_install/my5.7.cnf.bak
8 /root/mysql_5.7_install/my5.7.cnf.116
8 /root/mysql_5.7_install/my5.7.cnf
8 /root/centos7_init_jjy.sh
目录下的文件的大小,并且排序
# find . -type f -exec du -k {} \; | sort -nrk 1 | head
3821440 ./software.tar.gz
626760 ./mysql_5.7_install/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
617360 ./mysql5.7.v2.tar.gz
20 ./.mysql_history
12 ./mysql_5.7_install/my5.7.cnf.bak
8 ./mysql_5.7_install/my5.7.cnf.116
8 ./mysql_5.7_install/my5.7.cnf
8 ./centos7_init_jjy.sh
4 ./yum_config.sh.1
4 ./yum_config.sh
查看当前在线的用户并且排序
# users|tr ' ' '\n'|sort |uniq
root
使用perl的语法格式
# uptime | grep -Po '\d{2}\:\d{2}\:\d{2}'
21:43:4
last相关用法
# last reboot #查看重启的日志
reboot system boot 3.10.0-957.10.1. Thu Mar 19 11:36 - 21:45 (2+10:09)
reboot system boot 3.10.0-957.10.1. Mon Oct 28 14:51 - 11:20 (82+20:29)
reboot system boot 3.10.0-957.10.1. Tue Oct 15 11:14 - 13:30 (13+02:15)
reboot system boot 3.10.0-957.10.1. Fri Jul 26 10:58 - 09:03 (80+22:04)
reboot system boot 3.10.0-957.10.1. Fri Jul 5 10:25 - 13:04 (17+02:39)
reboot system boot 3.10.0-957.10.1. Wed Jul 3 15:49 - 13:04 (18+21:15)
reboot system boot 3.10.0-862.el7.x Fri Apr 12 14:37 - 13:04 (100+22:27)
reboot system boot 3.10.0-862.el7.x Fri Apr 12 14:34 - 13:04 (100+22:30)
reboot system boot 3.10.0-862.el7.x Fri Apr 12 14:33 - 13:04 (100+22:31)
reboot system boot 3.10.0-862.el7.x Fri Apr 12 14:26 - 14:33 (00:07)
wtmp begins Fri Apr 12 14:26:12 2019
# lastb #查看登录失败的次数
root ssh:notty localhost Sat Mar 21 15:15 - 15:15 (00:00)
root ssh:notty localhost Sat Mar 21 15:12 - 15:12 (00:00)
root ssh:notty localhost Sat Mar 21 15:12 - 15:12 (00:00)
root ssh:notty localhost Sat Mar 21 15:12 - 15:12 (00:00)
btmp begins Sat Mar 21 15:12:36 2020
查看某个用户的登录信息
# last root
root pts/2 172.16.13.3 Sat Mar 21 21:12 still logged in
root pts/1 172.16.13.3 Sat Mar 21 21:12 still logged in
root pts/0 172.16.13.3 Sat Mar 21 21:12 still logged in
root pts/2 172.16.13.3 Sat Mar 21 16:28 - 16:59 (00:30)
字符串的截取
# echo '/dev/sda1 521M 174M 347M 34% /boot'|egrep -o "[0-9]+%"
34%
# pursg=34%
# pursg=${pursg/\%/}
# echo $pursg
34
找出占用cpu最多的十个线程
# ps -eo comm,pcpu --sort -pcpu | head
COMMAND %CPU
systemd 0.0
kthreadd 0.0
ksoftirqd/0 0.0
kworker/0:0H 0.0
migration/0 0.0
rcu_bh 0.0
rcu_sched 0.0
lru-add-drain 0.0
watchdog/0 0.0
找出与zabbix进程相关的条目
# ps -eo comm,pcpu,pid,pmem|grep zabbix
zabbix_agentd 0.0 6479 0.0
zabbix_agentd 0.0 6502 0.0
zabbix_agentd 0.0 6503 0.0
zabbix_agentd 0.0 6504 0.0
zabbix_agentd 0.0 6505 0.0
zabbix_agentd 0.0 6506 0.0
找出给定的命令名所对应的经常ID
# ps -C bash -o pid=
26692
29138
29160 #或者是使用
# pgrep bash
26692
29138
29160
# pgrep bash -d : #指定分隔符
26692:29138:29160
# pgrep -u root bash #指定用户
26692
29138
29160
cat用法
ls | cat -n #加序号
1 1
2 1.log
3 1.session
4 3
5 3.txt
6 anaconda-ks.cfg
7 backup
8 baidu
9 centos7_init_jjy.sh
10 file3
11 mysql_5.7_install
12 mysql5.7.v2.tar.gz
13 software.tar.gz
14 test.sh
15 t.sh
16 yum_config.sh
17 yum_config.sh.1
# ls | cat -n>1
# cat 1
1 1
2 1.log
3 1.session
4 3
5 3.txt
6 anaconda-ks.cfg
# echo 'test'|cat - 1 #将字符串与文本内容拼接
test
1 1
2 1.log
3 1.session
4 3
5 3.txt
6 anaconda-ks.cfg
7 backup
8 baidu
9 centos7_init_jjy.sh
10 file3
11 mysql_5.7_install
12 mysql5.7.v2.tar.gz
13 software.tar.gz
14 test.sh
15 t.sh
16 yum_config.sh
17 yum_config.sh.1