[英]bash - find all .bashrc files and append to them
I need to find all .bashrc files and append "MYSQL_HISTFILE=/dev/null" to it, to remediate an issue. 我需要找到所有.bashrc文件并将“MYSQL_HISTFILE = / dev / null”附加到它,以修复问题。 There are alot of .bashrc files, so can I do something like: 有很多.bashrc文件,所以我可以这样做:
find / -type f -name ".bashrc" -exec echo "export MYSQL_HISTFILE=/dev/null" >> {} \;
>>
is executed by the original shell process, it can't use substitution from find
. >>
由原始shell进程执行,它不能使用find
替换。 And find
doesn't run its command through a shell, so it can't do output redirection itself. 并且find
不会通过shell运行它的命令,因此它本身不能进行输出重定向。
You need to execute bash
explicitly so you can use redirection in the command. 您需要显式执行bash
以便在命令中使用重定向。
find / -type f -name '.bashrc' -exec bash -c 'echo export MYSQL_HISTFILE=/dev/null >> "{}"' \;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.