如何在bash中使用echo with find?

rɑː*_*dʒɑ 3 bash find

我有10个文件.我可以列出它们,find . -type f我想要实现的是在使用find命令找到它们之后向所有10个文件发送消息.

我试过的, find . -type f -exec echo "This file found" >> {} \;

可能逻辑上我是对的,但它不起作用.有什么方法可以实现使用findecho只有?

谢谢

hee*_*ayl 7

shell重定向>>首先完成,{}即使在find启动之前也会创建一个名为的文件,并且字符串(文件的数量在那里)正被写入文件{}.

你需要:

find . -type f -exec bash -c 'echo "This file found" >>"$1"' _ {} \;
Run Code Online (Sandbox Code Playgroud)