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"' _ {} \;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With