I'm using a MacOS X. I know that this code in the terminal will replace all txt files that include "hello" with "hiThere" in the folder named "world":

perl -pi -w -e 's/hello/hiThere/g;' ~/Desktop/world/*.txt

But inside that world folder there are other folders which have other txt files in them, and those don't go through the refactor or the rename, you have to then individually type the additional folders using the above method.

Is there a method that does it automatically for you?


Use this :

find main_dir -type f -name '*.txt' -exec perl -pi -w -e 's/hello/hiThere/g;' {} \;

Replace main_dir by your main directory

  • where in the command do i input the parent folder who's internal fodlers i want checked? i.e "desktop/world/"? – kay Mar 28 '18 at 12:45
  • It's main_dir – Gilles Quenot Mar 28 '18 at 12:49
  • replace main_dir... By your own main dir – Gilles Quenot Mar 28 '18 at 12:51
  • @fixer1234 thisis done – Gilles Quenot Mar 28 '18 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.