简体   繁体   English

查找并替换特定目录中所有文件和文件夹中的字符串

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

相关问题 使用sed替换目录中所有文件中的字符串 - using sed to replace a string in all files of a directory BASH使用FIND和SED查找并替换目录中的所有文件 - BASH find and replace in all files in directory using FIND and SED 除了某些文件夹中的文件外,我如何将其所有文件包含在文件夹或目录中? - How do I tar a folder or directory with all of it's files except leave out files from certain folders? 如何用新的标头和尾部字符串替换目录中所有文件的标头和尾部,但最多只能确定一个字符? - How do I replace the header and trailer of all files in a directory with a new header and trailer string, but only up to a certain character? 使用 Linux 查找包含特定字符串的文件并复制到目录 - Find Files Containing Certain String and Copy To Directory Using Linux 替换字符串并在目录中的所有.html文件中包含日期 - Replace string and include date inside all .html files within a directory 在SSH中按名称查找和替换文件或文件夹 - Find And Replace Files Or Folders By Name In SSH 如何在* NIX服务器上查找包含特定字符串的所有文件 - How to find all files on a *NIX server containing a certain string Shell 命令到 tar 目录,不包括某些文件/文件夹 - Shell command to tar directory excluding certain files/folders 除了某些文件之外,递归查找和替换 - Find & replace recursively except for certain files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM