Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use echo with find in bash?

Tags:

find

bash

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

like image 744
rɑːdʒɑ Avatar asked Dec 24 '22 03:12

rɑːdʒɑ


1 Answers

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"' _ {} \;
like image 196
heemayl Avatar answered Jan 01 '23 16:01

heemayl