Shell Linux Unix xargs -i替换字符串

奥马尔·比斯塔米(Omar BISTAMI)

我很难理解此命令的xargs部分:

find -type f | sed 's/ /\\ /g' | xargs -ifil file fil | \
   grep ELF | grep executable | cut -d: -f1 | xargs -ifil find fil -exec chmod 744 {} \;

据我了解:寻找文件而不是目录,然后用“ \”替换“”,然后将输出传递给xargs并将其传递给命令文件?为什么-i用来代替?然后使用grep ELF和可执行文件,使用:delimeter占据第一列,再次使用与chmod 744相同的选项执行xargs?

伊尔卡楚

好了,是(不推荐使用的)替代方案,GNU手册页告诉您了-istr-I str-I

-I replace-str
      Replace  occurrences  of  replace-str  in the initial-arguments with 
      names read from standard input.  Also, unquoted blanks do not termi‐
      nate  input  items;  instead the separator is the newline character. 
      Implies -x and -L 1.

换句话说,使用-ixxx(或-Ixxx),在运行命令之前用当前项目xargs替换xxx给定命令中的字符串,并使xargs每个输入行仅运行一次给定命令,而不是将多个项目堆叠到一个命令中的默认设置命令调用,并将空格分隔的字符串视为不同的项目。

例如,在这里,该echo命令运行两次,并相应地xxx替换为两个输入行的内容:

$ printf "foo bar\nqwerty\n" | xargs -ixxx echo ":xxx:xxx:"
:foo bar:foo bar:
:qwerty:qwerty:

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章