linux的进程和管道符(二)

回顾:
进程管理:
kill killall pkill
问题:
1.pkill -u root 禁止
2.用户名不要用数字开头或者纯数字
windows的用户名不要用中文
3.pokit
/etc/passwd 640
chmod 644 /etc/passwd
yum reinstall -y polkit
/lib/polkit-1/polkitd
killall httpd
systemctl start httpd
selinux
getenforce
setenforce 0
SELINUX=disabled

4.进程管道技术

管道操作符号“|”连接左右两个命令,将左侧的命令的标准输出,交给右侧命令的标准输入

格式:cmd1 | cmd2 [...|cmdn]

[root@localhost ~]# head /etc/passwd | tail -5 | head -3
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt

案例l:将/etc/passwd中的用户按UID大小倒序排列,只看前10行 

[root@localhost ~]# sort -t: -k3 -n /etc/passwd
[root@localhost ~]# sort -t: -k3 -n /etc/passwd -r
[root@localhost ~]# sort -t: -k3 -n /etc/passwd -r | head

案例2:统计当前的/etc/passwd中的用户使用的shell类型

[root@localhost ~]# awk -F: '{print $7}' /etc/passwd 
[root@localhost ~]# awk -F: '{print $7}' /etc/passwd | sort
[root@localhost ~]# awk -F: '{print $7}' /etc/passwd | sort | uniq
[root@localhost ~]# awk -F: '{print $7}' /etc/passwd | sort | uniq -c | sort -rn
18 /sbin/nologin
2 /bin/bash
1 /sbin/shutdown
1 /sbin/halt
1 /bin/sync

案例3:统计出最占CPU的5个进程

[root@localhost ~]# ps aux --sort=-%cpu | head -6

案例4:统计网站的访问情况top20
//思路:打印所有访问的联机|过滤访问网站的连接|打印用户的IP|排序|去重

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# ss -an | grep :80 | awk -F":" '{print $8}' | sort | uniq -c
1 
[root@localhost ~]# ss -an | grep :80 | awk -F":" '{print $8}' | sort | uniq -c | sort -k1 -rn | head -n 20 
//方法2
[root@localhost ~]# awk '{print $1}' /var/log/httpd/access_log | sort | uniq -c | sort -rn | head -n 20
38 10.0.1.26
2 ::1

案例5:打印当前所有IP

[root@localhost ~]# ip a | grep 'inet ' | awk '{print $2}' | awk -F"/" '{print $1}'
127.0.0.1
10.0.1.31

案例6:打印根分区已用空间的百分比(仅打印数字)

[root@localhost ~]# df | grep '/$' | awk '{print $5}' | awk -F% '{print $1}'
9

5.tee管道技术

[root@localhost ~]# ip a | grep 'inet ' | tee ip.txt | awk '{print $2}' | awk -F"/" '{print $1}'
127.0.0.1
10.0.1.31

[root@localhost ~]# cat ip.txt 
inet 127.0.0.1/8 scope host lo
inet 10.0.1.31/24 brd 10.0.1.255 scope global noprefixroute ens33

重定向与tee的区别

[root@localhost ~]# date > date.txt
[root@localhost ~]# date | tee date.txt
2019年 12月 24日 星期二 14:46:56 CST
原文地址:https://www.cnblogs.com/xmtxh/p/12091686.html