> {} \;' I would like to add the ...">

Bash, find, exec and echo

find . \ -name 'user_prefs' \ -exec echo "whitelist_from basheer@hydrofitgroup.com" >> {} \;' 

I would like to add the line whitelist_from basheer@hydrofitgroup.com to all the files found by find , but my command does not work. It just creates the file '{}'.

Shoud do I use the for command?

thanks!

+8
command-line bash find for-loop
source share
2 answers

You need to exit "→", for example, like this:

 find . -name 'user_prefs' -exec sh -c 'echo "whitelist_from basheer@hydrofitgroup.com" >> {}' \; 
+10
source share

As already mentioned, using xargs is recommended, but you can also avoid running sh many times:

 find . -name 'user_prefs' | while read filename; do echo "whitelist_from basheer@hydrofitgroup.com" >>"$filename"; done 
+4
source share

Source: https://habr.com/ru/post/650242/


All Articles