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

What is the simplest way to complete the task?


2 Answers 2

rsync -v --backup --suffix=something ./patt*.py /other/path
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>? Mar 31, 2016 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>?" Apr 1, 2016 at 0:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .