开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜