Ubuntu – Copy and paste a bunch of files with different name

command linecptext processing

I have a bunch of text files with the name

foo_bar_abc_1_01_geh_original.in
foo_bar_abc_1_02_geh_original.in
foo_bar_abc_1_03_geh_original.in
...
...
foo_bar_abc_1_1000_geh_original.in

I would like to copy (and keep the original files) each file and paste to different names (in the same folder) like,

foo_bar_abc_1_01_geh_copy.in
foo_bar_abc_1_02_geh_copy.in
foo_bar_abc_1_03_geh_copy.in
...
...
foo_bar_abc_1_1000_geh_copy.in

How can I do this using a simple script?

Best Answer

Change directory to where you have the original files.

Then test with the following command line,

for i in *_original.*;do echo cp -p "$i" "${i/_original./_copy.}";done

and if it looks good, remove echo and do the copying,

for i in *_original.*;do cp -p "$i" "${i/_original./_copy.}";done