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

前端之家收集整理的这篇文章主要介绍了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.

原文链接:https://www.f2er.com/bash/384120.html

猜你在找的Bash相关文章