Jepessen
Jepessen

Reputation: 12435

Copy files `*XXX*` to `*YYY*`

I have a bunch of files with a XXX string in the name, like:

I want to take all these files and copy them in the same folder, changing XXX with another string YYY, so I obtain in the same folder:

How can I do it?

Upvotes: 1

Views: 789

Answers (2)

anubhava
anubhava

Reputation: 785611

In BASH you can do:

for f in *XXX*; do echo mv -i "$f" "${f/XXX/YYY}"; done

If you have rename utility then use:

rename 's/XXX/YYY/' *XXX*

Upvotes: 4

Micah Smith
Micah Smith

Reputation: 4471

Use the super helpful rename command. Think of it as rename from XXX to YYY on all files.

rename XXX YYY *

If you are looking to copy in addition to move, copy to some subdirectory first and then move back.

Upvotes: 2

Related Questions