2

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

2

1 Answer 1

3

From folder you want to change file names recursively:

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

Not the answer you're looking for? Browse other questions tagged .