Reputation: 809
find . \
-name 'user_prefs' \
-exec echo "whitelist_from [email protected]" >> {} \;'
I would like to add the line whitelist_from [email protected]
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!
Upvotes: 9
Views: 12192
Reputation: 1689
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 [email protected]" >>"$filename"; done
Upvotes: 5
Reputation: 1689
You have to escape the '>>', for example like this:
find . -name 'user_prefs' -exec sh -c 'echo "whitelist_from [email protected]" >> {}' \;
Upvotes: 12