I have a folder like this:


The new-content folder contains an on-going updated stuff that I update. When I want to update my content I am going to copy them to overwrite the existed ones, like this:

\cp -rf new-content/* ./

But how can I set up a backup of the going-to-be-overwritten files?

Any simple way to achieve this?


1 Answer 1


From man cp (the GNU version, found on Linux and Cygwin)


make a backup of each existing destination file

-b like --backup but does not accept an argument


touch 1 2
cp -bv 2 1
‘2’ -> ‘1’ (backup: ‘1~’)

Note that this does not check for existing backup files, i.e. if 1~ exists it will be overwritten. Using the long version you can avoid this. E.g.

cp -v --backup=numbered 2 1
‘2’ -> ‘1’ (backup: ‘1.~1~’)
cp -v --backup=numbered 2 1
‘2’ -> ‘1’ (backup: ‘1.~2~’)
cp -v --backup=numbered 2 1
‘2’ -> ‘1’ (backup: ‘1.~3~’)

You must log in to answer this question.

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