bash, find, exec and echo
11,539
Solution 1
You have to escape the '>>', for example like this:
find . -name 'user_prefs' -exec sh -c 'echo "whitelist_from [email protected]" >> {}' \;
Solution 2
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
Author by
Roberto
Updated on June 24, 2022Comments
-
Roberto almost 2 years
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 byfind
, but my command does not work. It just creates the file '{}'.Shoud i use the
for
command?thanks!
-
SourceSeeker over 13 yearsThis is a correct answer, but I wouldn't exactly call it "escaping".
-
SourceSeeker over 13 yearsThis is quite a bit faster than the
xargs
version.