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 files that are found 开发者_高级运维by find
, but my command does not work.
It just creates the file '{}'.
Shoud i use the for
command?
thanks!
You have to escape the '>>', for example like this:
find . -name 'user_prefs' -exec sh -c 'echo "whitelist_from basheer@hydrofitgroup.com" >> {}' \;
As said already, using xargs is encouraged, but you can also avoid executing sh many times by:
find . -name 'user_prefs' | while read filename; do echo "whitelist_from basheer@hydrofitgroup.com" >>"$filename"; done
精彩评论