日期:
来源:Linux公社收集编辑:聆听世界的鱼
点击上方蓝字 ● 关注Linux公社
xargs - 从标准输入读取数据流,然后生成并执行命令行。 tee - 从标准输入读取并同时写入标准输出和一个或多个文件。它更像是一个重定向命令。
$ command1 args | command2 args
或者
# command1 args | command2 args | command3 args ...
linuxmi@linuxmi /home/linuxmi/www.linuxmi.com
⚡ sudo su
[sudo] linuxmi 的密码:
Linux迷 www.linuxmi.com> dmesg | head
如何使用 xargs 运行命令
linuxmi@linuxmi /home/linuxmi/www.linuxmi.com
⚡ ls -1 *.sh
install.sh
linuxmi.com.sh
www.linuxmi.com.sh
linuxmi@linuxmi /home/linuxmi/www.linuxmi.com
⚡ ls -1 *.sh | xargs
install.sh linuxmi.com.sh www.linuxmi.com.sh
$ ls *.sh | xargs wc -l #统计每个文件的行数
$ ls *.sh | xargs wc -w #统计每个文件的字数
$ ls *.sh | xargs wc -c #统计每个文件的字符数
$ ls *.sh | xargs wc #计算每个文件中的行数、单词数和字符数
$ find . -name "linuxmi" -type d -print0 | xargs -0 /bin/rm -rf "{}"
带有选项操作的 find 命令可以-print0
在标准输出上打印完整的目录路径,后跟空字符和-0 xargs
标志处理文件名中的空格。
如何在 Linux 中通过命令使用 Tee
$ ps -eo cmd,pid,ppid,%mem,%cpu --sort=-%mem | head | tee linuxmi.com.txt
$ cat topprocs.txt
-a
标志。linuxmi@linuxmi /home/linuxmi/www.linuxmi.com
⚡ ps -eo cmd,pid,ppid,%mem,%cpu --sort=-%mem | head | tee -a linuxmi.com.txt
$ man xargs
$ man tee
链接:https://www.linuxmi.com/linux-tee-xargs.html
关注我们 长按或扫描下面二维码关注 Linux公社
关注 Linux公社,添加“ 星标 ”
每天 获取 技术干货,让我们一起成长
合作联系:root@linuxidc.net