当前位置:网站首页>26. Pipeline parameter substitution command xargs

26. Pipeline parameter substitution command xargs

2022-08-09 13:16:00 51CTO

Use is mentioned abovelocate命令及find命令查找文件,本文主要介绍xargsFunctions and command options;

1、备份配置文件,并添加bak这个扩展名

26、Pipeline parameter substitution commandxargs_html

26、Pipeline parameter substitution commandxargs_html_02



xargs The command is to readStandard input and data from pipesIt is used as an argument to other commands to make up for the lack of some commands that do not support piped data input,Generally used for pipes;如下所示:

26、Pipeline parameter substitution commandxargs_分隔符_03

      
      
cat /etc/shadow | echo
  • 1.

26、Pipeline parameter substitution commandxargs_xargs_04

      
      
cat /etc/shadow | xargs echo
使用xargs命令将cat /etc/shadow Normalized output is piped,xargsSupply these as arguments to
  • 1.
  • 2.

xargs选项:

-d  分隔符 :Think by defaultxargs使用空白、tab、The carriage return is passed to the following command as a parameter separator,可以使用-d指定分隔符

26、Pipeline parameter substitution commandxargs_分隔符_05

-p 交互式命令

26、Pipeline parameter substitution commandxargs_分隔符_06

-n 表示将xargs生成的命令行参数,Pass several at a time to subsequent executions

26、Pipeline parameter substitution commandxargs_find命令_07

-0 表示以\0as a sub-payment,一般用于find命令,Cannot be used due to file namingNUM字符串,使用-0,Argument separation errors can be avoided

使用方式   find . -name "*.txt" -print0 | xargs -0 echo   (-print0 Indicates that it is added after the result of the search\0而不是换行符

-i 或者是-I,这得看linux支持了,将xargs的每项名称,一般是一行一行赋值给 {},可以用 {} 代替

-P 修改最大的进程数,默认是1,为0时候为as many as it can 

      
      
seq 100 |xargs -i -P10 wget -P /data http://www.baidu.com/image{}.html
并发执行10个进程,http://www.baidu.com/image1.html——http://www.baidu.com/image10.html每次10个
  • 1.
  • 2.

练习:

1、查找/var下属主为root and the owner ismail的所有文件

26、Pipeline parameter substitution commandxargs_分隔符_08

2、查找/var目录下不属于root、lp、gdm的所有文件

26、Pipeline parameter substitution commandxargs_find命令_09

3、查找/varThe directory has been modified in the last week,同时属主不为root 也不是postfix的文件

26、Pipeline parameter substitution commandxargs_html_10

4、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件

26、Pipeline parameter substitution commandxargs_分隔符_11

5、Find greater than1M且类型为普通文件的所有文件

26、Pipeline parameter substitution commandxargs_xargs_12

6、查找/etc目录下所有用户都没有写权限的文件

26、Pipeline parameter substitution commandxargs_分隔符_13

7、查找/etc目录下至少有一类用户没有执行权限的文件

26、Pipeline parameter substitution commandxargs_find命令_14

8、查找/etc/init.d目录下,所有用户都有执行权限,且其它用户有写权限的文件

26、Pipeline parameter substitution commandxargs_xargs_15

原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091152353942.html