[英]Find and replace string in all files and folders in a certain directory
I have SSH access to a web hosting server. 我可以通过SSH访问网络托管服务器。 There are several thousand files, most of which contain the string 'Copyright ABC'.
有数千个文件,其中大多数包含字符串'Copyright ABC'。
I would like to change the string in the (and all files in the sub-folders) code of all of these files to 'Copyright XYZ' as our company has acquired the old site and we must change the footer. 我想将所有这些文件(以及子文件夹中的所有文件)代码中的字符串更改为“ Copyright XYZ”,因为我们公司已经获得了旧站点,因此我们必须更改页脚。
使用find
获取文件,然后使用xargs
将它们与sed
一起使用
find /your/path -type f -print0 | xargs -0 sed -i 's!Copyright ABC!Copyright XYZ!g'
find . -type f -exec sed -i 's/Copyright ABC/Copyright XYZ/g' {} +
我喜欢Perl派!
find /your/path/ -type f -exec perl -p -i -e's/Copyright ABC/Copyright XYZ/g' {} \;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.