I'm trying to append a fixed string to each file in a folder (and its subfolders) whilst skipping the .git directory.
I expected that something like this would work
find . -type f ! -path "./.git/*" -exec "echo \"hello world\" >> {}" \;
and if I run it with an additional echo it does generate commands that look right
bash> find . -type f ! -path "./.git/*" -exec echo "echo \"hello world\" >> {}" \;
echo "hello world" >> ./foo.txt
echo "hello world" >> ./bar.txt
...
and those commands do what I want when I run them directly from the shell but when I run it from find I get this:
bash> find . -type f ! -path "./.git/*" -exec "echo \"hello world\" >> {}" \;
find: echo "hello world" >> ./foo.txt: No such file or directory
find: echo "hello world" >> ./bar.txt: No such file or directory
...
but those files do exist because when I list the directory I get this:
bash> ls
bar.txt baz.txt foo.txt subfolder/
I guess that I'm not quoting something I need to but I've tried everything I can think of (double and single quote, escaping and not escaping the inner quotes etc...).
Can someone explain what is wrong with my command and how to achieve the the addition of the fixed string to the files?
You need to instruct the shell to do it:
find . -type f ! -path "./.git/*" -exec sh -c "echo hello world >> {}" \;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments