揮発性のメモ2

http://d.hatena.ne.jp/iww/

再帰的にファイル内の文字列を検索して置換する

http://hoge.example.comhttps://hoge.example.com に置き換えるやつ

# findでやる方法
find . -type f | xargs sed -e 's/http:\/\/hoge\.example\.com/https:\/\/hoge.example.com/m' -i

# grepでやる方法
grep -rIl http://hoge.example.com . | xargs sed -e 's/http:\/\/hoge\.example\.com/https:\/\/hoge.example.com/m' -i

grepのオプション

-r 再帰
-I バイナリは無視
-l ファイル名表示だけ

findだと検索対象にバイナリも含んでしまうし、全ファイルのタイムスタンプが書き換わってしまう。
grepなら対象を選べるし、バイナリも除外できるし、タイムスタンプの更新も必要最小限にできるので、grepをちゃんと使おう