如何使用echo在bash中查找? [英] how to use echo with find in bash?

查看:148
本文介绍了如何使用echo在bash中查找?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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中查找?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆