Linux shell:批量替换文件内容和批量重命名文件

1、批量替换指定多个文件的文件内容

在指定目录/your/path里,查找包含old_string字符串的所有文件,并用new_string字符串替换old_string字符串。

sed -i "s/old_string/new_string/g"  `grep old_string -rl /your/path`

2、批量修改指定多个文件的文件名

在指定的路径/your/path下,查找以old_name字符串开头的所有文件,并以new_string替换掉old_string字符串。

find /your/path -name 'old_name*' | xargs -i echo mv {
    
    } {
    
    } | sed 's/old_name/new_name/2' | sh

本文转自:https://blog.csdn.net/segments/article/details/50977693

猜你喜欢

转载自blog.csdn.net/weixin_44498318/article/details/107333329
今日推荐