简体   繁体   English

bash - 找到所有.bashrc文件并附加到它们

[英]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.

相关问题 如何在linux中使用bash查找所有.sh文件并使它们可执行? - How to find all .sh files and make them executable using bash in linux? 使用bash,如何查找所有包含特定字符串的文件并将其替换为现有文件? - Using bash, how do I find all files containing a specific string and replace them with an existing file? 查找所有带有扩展名的文件并查看它们 - Find all files with an extension and view them 如何在 bash 中找到一些文件并将它们输入到另一个程序中? - How to find some files and input them to another program in bash? Bash:查找包含特定字符串的文件并将它们复制到文件夹中 - Bash: Find files containing a certain string and copy them into a folder BASH使用FIND和SED查找并替换目录中的所有文件 - BASH find and replace in all files in directory using FIND and SED bash和.bashrc中的怪异行为 - Weird behavior in bash and .bashrc 每次我更改bashrc目录时列出所有文件的脚本? - Script to list all files each time I change directory for bashrc? 在/ template文件夹中找到所有* .tpl文件并对其进行chmod 666 - Find all *.tpl files in /template folder and chmod them 666 recursively 在linux系统上找到所有与'name'匹配的文件,并用它们搜索'text' - Find all files matching 'name' on linux system, and search with them for 'text'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM