
我使用的是 MacOS X。
perl -pi -w -e 's/hello/hiThere/g;' ~/Desktop/world/*.txt
但在該 world 資料夾內還有其他資料夾,其中包含其他 txt 文件,且這些資料夾不會經過重構或重新命名,您必須使用上述方法單獨鍵入其他資料夾。
有沒有一種方法可以自動為您完成此操作?
答案1
用這個 :
find main_dir -type f -name '*.txt' -exec perl -pi -w -e 's/hello/hiThere/g;' {} \;
替換main_dir
為您的主目錄