bash – 用于递归搜索和替换文本的Unix命令

我正在寻找一个UNIX命令,帮助我递归地从文件夹中的所有文件中搜索文本,并用新值替换它.在网上搜索后,我遇到了这个对我有用的命令.

find ./myFolder -type f -print0 | xargs -0 sed -i ‘s/Application/whatever/g’

请帮助我理解上面的命令.我无法理解命令的这一部分:-print0 | xargs -0,这表示什么?我只知道Unix中的基础知识,因此很难理解这一点.我正在使用bash shell.

还有任何替代命令在Unix中提供相同的功能,从谷歌搜索我得到了与Perl脚本相关的命令,我不知道Perl因此放弃了使用它的想法.

Also are there any alternate commands that provides same functionality in Unix

是的,你可以做到这一切:

find ./myFolder -type f -exec sed -i 's/Application/whatever/g' '{}' \;

find中的-exec选项适用于:

-exec utility [argument ...] ; True if the program named utility returns a zero value as its exit status. Optional arguments may be passed to the utility. The expression must be terminated by a semicolon (”;”). If you invoke find from a shell you may need to quote the semicolon if the shell would otherwise treat it as a control operator. If the string ”{}” appears anywhere in the utility name or the arguments it is replaced by the pathname of the current file. Utility will be executed from the directory from which find was executed. Utility and arguments are not subject to the further expansion of shell patterns and constructs.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...