[root@~]# ll /dev/ |less
[root@ ~]# ps aux |grep 'sshd'
[root@ ~]# rpm -qa |grep 'httpd' //查询所有安装的软件包,过滤包含httpd的包
[root@ ~]# yum list |grep 'httpd'
[root@~]# //以: 分隔,将第三列按字数升序
[root@~]# sort -t":" -k3 -n /etc/passwd -r //逆序
[root@~]# sort -t":" -k3 -n /etc/passwd |head
-t 指定字段分隔符–field-separator
-k 指定列
-n 按数值
[root@~]# ps aux --sort=-%cpu |head -6
思路:取出第七列(shell) | 排序(把相同归类)| 去重
[root@~]# awk -F: '{print $7}' /etc/passwd
[root@~]# awk -F: '{print $7}' /etc/passwd |sort
[root@~]# awk -F: '{print $7}' /etc/passwd |sort |uniq
[root@~]# awk -F: '{print $7}' /etc/passwd |sort |uniq -c
131 /bin/bash
1 /bin/sync
1 /sbin/halt
63 /sbin/nologin
1 /sbin/shutdown
-F: 指定字段分隔符
$7 第七个字段
思路: 打印所有访问的连接 | 过滤访问网站的连接 | 打印用户的IP | 排序 | 去重
[root@~]# yum -y install httpd
[root@~]# systemctl start httpd
[root@~]# systemctl stop firewalld
[root@~]# ss -an |grep :80 |awk -F":" '{print $8}' |sort |uniq -c
4334 192.168.0.66
1338 192.168.10.11
1482 192.168.10.125
44 192.168.10.183
3035 192.168.10.213
375 192.168.10.35
362 192.168.10.39
[root@~]# ss -an |grep :80 |awk -F":" '{print $8}' |sort |uniq -c |sort -k1 -rn |head -n 20
[root@~]# ip addr |grep 'inet ' |awk '{print $2}' |awk -F"/" '{print $1}'
127.0.0.1
192.168.2.115
[root@~]# df -P |grep '/$' |awk '{print $5}' |awk -F"%" '{print $1}'
[root@~]# ip addr |grep 'inet ' |tee ip.txt |awk -F"/" '{print $1}' |awk '{print $2}'
127.0.0.1
172.16.60.1
[root@~]# cat ip.txt
inet 127.0.0.1/8 scope host lo
inet 172.16.60.1/24 brd 172.16.60.255 scope global eth0
[root@~]# ip addr |grep 'inet ' |tee -a ip.txt |awk -F"/" '{print $1}' |awk '{print $2}'
127.0.0.1
172.16.60.1
[root@~]# date >date.txt
[root@~]# date |tee date.txt
[root@~]# top -d 1 -b -n 1 > top.txt
[root@~]# top -d 1 -b -n 1 |tee top.txt
awk sed grep sort uniq less more xargs
xargs: ls cp rm
[root@localhost ~]# touch /home/file{1..5}
[root@localhost ~]# vim files.txt
/home/file1
/home/file2
/home/file3
/home/file4
/home/file5
[root@localhost ~]# cat files.txt |ls -l
[root@localhost ~]# cat files.txt |rm -rvf
cont.
[root@localhost ~]# cat files.txt |xargs ls -l
-rw-r--r--. 1 root root 0 Mar 11 10:35 /home/file1
-rw-r--r--. 1 root root 0 Mar 11 10:35 /home/file2
-rw-r--r--. 1 root root 0 Mar 11 10:35 /home/file4
-rw-r--r--. 1 root root 0 Mar 11 10:35 /home/file5
[root@localhost ~]# cat files.txt |xargs rm -rvf
removed ‘/home/file1’
removed ‘/home/file2’
removed ‘/home/file4’
removed ‘/home/file5’
[root@localhost ~]# touch /home/file{1..5}
[root@localhost ~]# cat files.txt |xargs -I {} ls -l {}
-rw-r--r--. 1 root root 0 Mar 11 10:40 /home/file1
-rw-r--r--. 1 root root 0 Mar 11 10:40 /home/file2
-rw-r--r--. 1 root root 0 Mar 11 10:40 /home/file4
-rw-r--r--. 1 root root 0 Mar 11 10:40 /home/file5
[root@localhost ~]# cat files.txt |xargs -I {} cp -rvf {} /tmp
‘/home/file1’ -> ‘/tmp/file1’
‘/home/file2’ -> ‘/tmp/file2’
‘/home/file4’ -> ‘/tmp/file4’
‘/home/file5’ -> ‘/tmp/file5’
[root@localhost ~]# cat files.txt |xargs -I YANG cp -rvf YANG /var/tmp
‘/home/file1’ -> ‘/var/tmp/file1’
‘/home/file2’ -> ‘/var/tmp/file2’
‘/home/file4’ -> ‘/var/tmp/file4’
‘/home/file5’ -> ‘/var/tmp/file5’
[root@localhost ~]# find /etc -iname "*ifcfg*" |xargs -I {} cp -rf {} /tmp