1. 程式人生 > >[常用shell命令] 批量替換檔案內容和檔名

[常用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