管道技术
- |:将管道符左边命令的标1 准输出,交给管道符右边命令的标准输入处理
管道技术—tee
tee
-a:append 追加
# 输出到设备
[root@localhost ~]# echo "$RANDOM" |tee /dev/pts/0 | passwd --stdin lx15
1150
# 输出到文件
[root@localhost ~]# echo "$RANDOM" |tee /work/AAA.txt | passwd --stdin lx15
[root@localhost ~]# cat AAA.txt
8904
管道技术—xargs
xargs:处理数据流,有些命令如果没有标准输入可以使用xargs
# xargs命令:
# 1.将管道符前面的标准输出进行排列
# 2.将排列后的内容,放到后面命令结尾处理
xargs:
-i:指定数据流的位置,将数据流放入{}中
[root@localhost ~]# find /opt/ -size -1k |xargs -i mv {} /tmp
## 具体使用,要看需求:
## 没有标准输入的命令,可以用xargs,有标准输入的命令也可以用,效果不同
###举例1:
[root@localhost~]# cat 888.txt
999.txt
aaaa.txt
[root@localhost~]# cat aaaa.txt
123
SASA
a233
b345
[root@localhost~]# cat 999.txt
456
345
134
237
[root@localhost~]# cat 888.txt | xargs sed 's#3#theree#g'
456
theree45
1theree4
2theree7
12theree
SASA
a2thereetheree
btheree45
[root@localhost~]# cat 999.txt aaaa.txt | sed 's#3#theree#g'
456
theree45
1theree4
2theree7
12theree
SASA
a2thereetheree
btheree45
[root@localhost~]# cat 888.txt |sed 's#3#theree#g'
12theree
2theree4
theree45
1theree6
2theree6
###举例2:
[root@localhost~]# cat 888.txt 999.txt
123
234
345
136
236
456
345
134
237
[root@localhost~]# ls 888.txt 999.txt
888.txt 999.txt
[root@localhost~]# ls 888.txt 999.txt | sed 's#3#theree#g'
888.txt
999.txt
[root@localhost~]# ls 888.txt 999.txt |xargs sed 's#3#theree#g'
12theree
2theree4
theree45
1theree6
2theree6
456
theree45
1theree4
2theree7
思维导图