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!
You need to exit "→", for example, like this:
find . -name 'user_prefs' -exec sh -c 'echo "whitelist_from basheer@hydrofitgroup.com" >> {}' \; 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