如何在 bash 中使用 echo 和 find ?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38843212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to use echo with find in bash?
提问by rɑ?d?ɑ
I have 10 files. I can list them with find . -type f
and what I am trying to achieve is sending a message to all 10 files after finding them with find command.
我有 10 个文件。我可以列出它们,find . -type f
我想要实现的是在使用 find 命令找到它们后向所有 10 个文件发送一条消息。
What I have tried, find . -type f -exec echo "This file found" >> {} \;
我所尝试的, find . -type f -exec echo "This file found" >> {} \;
May be logically I am right but its not working. Is there any way I can achieve with using find
and echo
only ?
可能在逻辑上我是对的,但它不起作用。有什么办法可以通过使用find
and echo
only来实现吗?
Thank you
谢谢
回答by heemayl
The shell redirection, >>
is being done at first, a file named {}
is being created before even the find
starts and the strings (the number of files are in there) are being written to the file {}
.
外壳重定向>>
首先正在完成,{}
甚至在find
开始之前就创建了一个名为的文件,并且正在将字符串(其中的文件数)写入文件{}
。
You need:
你需要:
find . -type f -exec bash -c 'echo "This file found" >>""' _ {} \;