1

I want to copy (or move) some files like cp ./patt*.py /other/path. However /other/path/ already contents files with the same names. So, I would like copy with renaming (adding some suffix, for example):

./pattfoo.py - copy to - /other/path/pattfoo.py_other
./pattbar.py - copy to - /other/path/pattbar.py_other
./pattfur.py - copy to - /other/path/pattfur.py_other
etc.

What is the simplest way to complete the task?

  • rename first and then copy – Anthon Mar 31 '16 at 11:36
  • @Anthon That's certainly not the simplest way. – Gilles Mar 31 '16 at 23:19
2
rsync -v --backup --suffix=something ./patt*.py /other/path
0
cd <old_path>
rename "s/.py/.py.rename/" *.py
mv *.py.rename <new_path>
  • What if foo.py exists in <old_path> and foo.py.rename exists in <new_path>? – Gilles Mar 31 '16 at 23:20
  • 1
    @Gilles: You might as well post that comment on the question — the OP seems to assume that he (or she) can copy (or move) ./foo.py to /other/path/foo.py_other without collision.  Perhaps the more interesting question is "What if foo.py and foo.py.rename both exist in <old_path>?" – G-Man Apr 1 '16 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.