This question already has an answer here:

I have a lots of log file in a directory and it's sub directory named as dataupload_sales_.xxx.com.dat. I wanted to change all files xxx.com part to yyy.com in current and sub directories.

i hope it's not a duplicate post as i have search the forum and tried few option but none of them worked. some post suggested to use rename and it's only rename in single file. where i have 5000+ sub directories in my directory and every sub directories have 100+ .dat files.

i have also tried

find ./ -name "xxx.com" -exec bash -c 'mv $0 $(echo "$0" | sed -r \"s|xxx.com|yyy.com|g\")' '{}' \;

it shows invalid directory error

marked as duplicate by Jacob Vlijm, heemayl command-line Feb 23 '16 at 9:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


From folder you want to change file names recursively:

find . -name '*.xxx.com.dat' -exec rename 's/xxx/yyy/' -- {} +
  • Thank You for your answer, it will change files in sub directory's too. – Himel Feb 23 '16 at 9:51
  • supposed to do it – EdiD Feb 23 '16 at 10:00

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