linux系统管理
管道技术
什么是管道符
管道符左边命令的标准输出交给管道符右边命令的标准输入来处理,错误输出无法处理
案例
1: 将/etc/passwd 中的UID取出并按大小排
root@localhost[15:10:02]:~
$ sort -t ':' -k3 -nr /etc/passwd
2: 统计当前/etc/passwd 中用户使用的 shell 类型
root@localhost[15:14:51]:~
$ awk -F ':' '{print $7}' /etc/passwd|sort|uniq -c
3: 打印本地的所有IP
root@localhost[15:43:25]:~
$ ifconfig | grep -w 'inet'| awk '{print $2}'

tee管道技术
选项 :-a
表示追加
案例 创建5个用户 并且给其赋予随机密码取前8位,同时把密码保存在a.txt的文件中
root@localhost[15:52:10]:~
$ seq 5|awk '{print "useradd lj"$1 ";echo $RANDOM|md5sum|cut -c 1-8|tee -a /tmp/a.txt |passwd --stdin lj"$1}'|bash

参数传递xargs
x 作用 将原本没有标准输入的命令,收到xargs的标准输入中,在传递给后面的命令使用选项 -I {} : 将数据流保存到大括号,后面命令可以直接调用 -n : 将前面的数据以列的方式排,指定数字是几,一行就有几个