4

I have a folder like this:

./folder-a/index.html
./folder-b/index.html
./folder-c/subdir/index.html
./new-content/folder-a/index.html
./new-content/folder-b/index.html
./new-content/folder-c/subdir/index.html

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?

0

1 Answer 1

8

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

--backup[=CONTROL]

make a backup of each existing destination file

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

Example

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 .