how to use echo with find in bash?

为君一笑 提交于 2019-12-22 10:09:04

问题


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


回答1:


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"' _ {} \;


来源:https://stackoverflow.com/questions/38843212/how-to-use-echo-with-find-in-bash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!