问题描述
我有10个文件。我可以用 find找到它们。 -type f
,我试图实现的是发现一个消息后,所有10个文件找到他们与find命令。 我试过了, find。 -type f -exec echo找到这个文件>> {} \;
可能在逻辑上我是对的,但是不能工作。使用 find
和 echo
只能用我的方式实现吗?
谢谢
shell重定向,>>
正在完成,一个名为 {}
的文件即使在 find
开始时也被创建,字符串(文件的数量)被写入文件 {}
。
您需要:
find。 -type'f -exec bash -c'echo找到这个文件>>$ 1'_ {} \;
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.
What I have tried, 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 ?
Thank you
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 {}
.
You need:
find . -type f -exec bash -c 'echo "This file found" >>"$1"' _ {} \;
这篇关于如何使用echo在bash中查找?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!