我正在使用xargs尝试回显文件名,然后回显其内容。这是命令
find output/ -type f | xargs -I {} sh -c "echo {} ; cat {}"
但是,由于某些原因,第二个替换之后的cat内容不会被替换。仅适用于某些文件,因此某些文件可以正常工作。
明确地说,我不是在寻找让我回显文件名和文件内容的命令,而是试图了解为什么此特定命令不起作用。
原来,该命令太长,因此它使用较短的文件名,而使用较长的文件名则失败。从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.