为什么xargs不替换第二个{}

Car*_*cas 3 xargs

我正在使用xargs尝试回显文件名,然后回显其内容。这是命令

find output/ -type f | xargs -I {} sh -c "echo {} ; cat {}"

但是,由于某些原因,第二个替换之后的cat内容不会被替换。仅适用于某些文件,因此某些文件可以正常工作。

明确地说,我不是在寻找让我回显文件名和文件内容的命令,而是试图了解为什么此特定命令不起作用。

Car*_*cas 8

原来,该命令太长,因此它使用较短的文件名,而使用较长的文件名则失败。从man xargs

-I replstr Execute utility for each input line, replacing one or more occurrences of replstr in up to replacements (or 5 if no -R flag is specified) arguments to utility with the entire line of input. The resulting arguments, after replacement is done, will not be allowed to grow beyond 255 bytes; this is implemented by concatenating as much of the argument containing replstr as possible, to the constructed arguments to utility, up to 255 bytes. The 255 byte limit does not apply to arguments to utility which do not contain replstr, and furthermore, no replacement will be done on utility itself. Implies -x.

  • 同样来自联机帮助页: -S replsize 指定 -I 可用于替换的空间量(以字节为单位)。replsize 的默认值为 255。我可以通过指定 `xargs -S 100000 -I {} <rest of command>` 将 xargs 与长命令一起使用。 (9认同)
  • 我对此进行了深入研究,发现在 Linux 上运行时我没有遇到命令长度问题,只有在 mac 操作系统上才遇到。我上面提到的手册页来自 mac os。 (2认同)