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?
Change directory to where you have the original files.
Then test with the following command line,
and if it looks good, remove
echo
and do the copying,You can use
mcp
from themmv
package in the following way: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. Usingmmv
has the advantage overcp
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):or, if that gives the “Argument list too long” error:
Example run
Let’s
time
it, run over 1000 files of 100 KiB each on a slow machine: