写入查找命令中的所有文件匹配项

Write to all file matches in find command

我想在 linux shell 中使用 查找命令 将一些文本回显到所有匹配的文件中。我试过这个” find . -type f -name "file*.txt" -exec echo "some text" > - '{}' ';' 但这没有 work.Is 无论如何我可以解决这个问题?

您的命令无效,因为 > 被 shell 解释为 shbash。使用 find -exec echo 时仅启动 echo。没有 shell 可以将 > 解释为重定向。

注意 > over 写入文件。您可能想要 append。使用 >> 这样做。

find . -type f -name 'file*.txt' -exec sh -c 'echo "some text" >> "[=10=]"' {} \;