1. 程式人生 > >shell 遍歷目錄下字尾名為.html的檔案,並替換檔案中內容

shell 遍歷目錄下字尾名為.html的檔案,並替換檔案中內容

1、shell查詢 .html檔案,例:

find /usr/local/guotom/webapps/ZingMH/nodeJs/tpls/views/ -type f -name '*.html'

2、替換方法

sed -i "s/邀請/呵呵/g"【將邀請替換為呵呵】

3、查詢並替換

find /usr/local/guotom/webapps/ZingMH/nodeJs/tpls/views/ -type f -name '*.html'|xargs sed -i "s/邀請/呵呵/g"【查詢/usr/local/guotom/webapps/ZingMH/nodeJs/tpls/views/目錄下所有html檔案中的內容並將檔案中邀請替換為呵呵】