简体   繁体   中英

Find and replace string in all files and folders in a certain directory

I have SSH access to a web hosting server. There are several thousand files, most of which contain the string '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.

使用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' {} \;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM