Copy and paste a bunch of files with different name
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
You can use mcp
from the mmv
package in the following way:
mcp "*original*" "#1copy#2"
This will copy every file containing the string “original” in the current directory and replace this string with “copy”. You can test what mcp
will do by adding the -n
flag, however it will not silently overwrite files, but ask you. Using mmv
has the advantage over cp
that you don’t have to call it for every single file – with one thousand files like you seem to copy, that makes a difference.
You could also use GNU parallel
in the following way (--dry-run
is for testing, remove it to perform the copying):
parallel --dry-run cp -p "{}" "{=s/original/copy/=}" ::: *
or, if that gives the “Argument list too long” error:
printf "%s\0" * | parallel --dry-run -0 cp -p "{}" "{=s/original/copy/=}"
Example run
$ ls -1
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_04_geh_original.in
$ mcp "*original*" "#1copy#2"
$ ls -1
foo_bar_abc_1_01_geh_copy.in
foo_bar_abc_1_01_geh_original.in
foo_bar_abc_1_02_geh_copy.in
foo_bar_abc_1_02_geh_original.in
foo_bar_abc_1_03_geh_copy.in
foo_bar_abc_1_03_geh_original.in
foo_bar_abc_1_04_geh_copy.in
foo_bar_abc_1_04_geh_original.in
Let’s time
it, run over 1000 files of 100 KiB each on a slow machine:
$ time mcp "*original*" "#1copy#2"
real 0m1.114s
user 0m0.000s
sys 0m0.132s