Hey guys, I am hoping someone can help me use the suffix argument in cp. I have tried every variation google had to offer and still couldn’t get it working. The background is that I want a folder copied to a slave hard drive each night, however if the same file exists I don’t want it over written, but to have a number appended to it. I’ve gone through the man pages, but what I really want is an example of it’s use and syntax. Thanks in advance.
AFAICT the --suffix option just overrides the default ~.
What you want is actually the --backup=numbered option. See the man page. Here’s an example:
$ touch foo
$ cp foo /tmp
$ cp --backup=numbered foo /tmp
$ ls /tmp/foo*
/tmp/foo /tmp/foo.~1~
Thats WAAAAAY cool for a quick backup-now/check-later. Thanks!
shell commands ARE fantastic! Now on to write a GUI
But, can it do this only if files are different? (man page, I know
Hi
You may want to look at rsync then…
–
Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.1 x86 Kernel 2.6.27.7-9-default
up 10:28, 2 users, load average: 0.00, 0.00, 0.01
GPU GeForce 6600 TE/6200 TE - Driver Version: 180.22
I’ve tried doing exactly what you have listed: cp -R --backup=numbered ./test1/ ./test2/ but nothing happens. It just copies the files from one directory to another over-writting the files already present.
$ cd /tmp
$ mkdir test1 test2
$ touch test1/foo test2/foo
$ cp -R --backup=numbered test1/* test2/
$ ls test2
foo foo.~1~
Looking at your command it looks like you would make a complete copy of test1 inside test2, maybe not what you had in mind. Try:
cp -R --backup=numbered test1/. test2/