Rob*_*rto 8 bash command-line for-loop find
find . \
-name 'user_prefs' \
-exec echo "whitelist_from basheer@hydrofitgroup.com" >> {} \;'
Run Code Online (Sandbox Code Playgroud)
我想将行添加whitelist_from basheer@hydrofitgroup.com到找到的所有文件中find,但我的命令不起作用.它只是创建文件"{}".
我用这个for命令?
谢谢!
Bal*_*sár 12
你必须逃避'>>',例如:
find . -name 'user_prefs' -exec sh -c 'echo "whitelist_from basheer@hydrofitgroup.com" >> {}' \;
Run Code Online (Sandbox Code Playgroud)
如前所述,鼓励使用xargs,但您也可以通过以下方式避免执行多次sh:
find . -name 'user_prefs' | while read filename; do echo "whitelist_from basheer@hydrofitgroup.com" >>"$filename"; done
Run Code Online (Sandbox Code Playgroud)