Mass Rename inside Files including sub directories

198 Views Asked by At

I have many file having "example.com" in them and I want to replace it with "example.co" as i change my site tld, i have rename program installed in my server and have root access too.

Can anybody help me in renaming it.

Sample location of files:

/var/html/downloads/folder1/folder1-1/abc(example.com).mp4
/var/html/downloads/folder2/folder2-1/abc(example.com).mp4
/var/html/downloads/folder2/folder2-2/abc(example.com).mp4
/var/html/downloads/folder3/folder3-1/abc(example.com).mp4

I hope some1 will help me out here :)

PS: I used this cmd but got below error:

cmd: find -name "*example*" | xargs -I '{}' rename s/com/co/ '{}'

Error:

For more details see rename(1).
rename: not enough arguments

Usage:
rename [options] expression replacement file...
1

There are 1 best solutions below

1
On BEST ANSWER

You don't want to rename but to substitute files in place so the right tool is :

find -name '*example*' | xargs -I '{}' sed -i 's/\.com$/.co/' '{}'