Bash – How to copy multiple files by wildcard

bashfile-copywildcards

I have a folder with a number of files in it ABC.* (there are roughly 100 such files). I want to duplicate them all to new files with names starting with DEF.*

So, I want

ABC.Page1
ABC.Page2
ABC.Topic12
...etc

copied to

DEF.Page1
DEF.Page2
DEF.Topic12
...etc

What is the simplest way to do this with a batch command (in BASH or similar)? I am thinking something involving sed or awk or xargs, but I'm having difficulty figuring out the syntax. I could write a Python script, but I'm thinking there is probably a command line solution that is not too complicated.

Best Answer

How about something like this in bash:

for file in ABC.*; do cp "$file" "${file/ABC/DEF}";done

you can test it by putting echo in front of the cp command:

for file in ABC.*; do echo cp "$file" "${file/ABC/DEF}";done
Related Question