...making Linux just a little more fun!
Smile Maker [britto_can at yahoo.com]
Folks:
When you do scp to remote machine, linux assumes to overwrite the target file if exists. Is there any way to check whether the target file exists and then copy the actual file.
--- Britto
Thomas Adam [thomas.adam22 at gmail.com]
2008/7/22 Smile Maker <britto_can@yahoo.com>:
> Folks: > > When you do scp to remote machine, linux assumes to overwrite the target > file if exists.Is there any way to check whether the target file exists and > then copy the actual file.
Not directly, no. The best solution I can come up with is to use rsync over SSH which will allow for things like --update and --backup.
-- Thomas Adam
Ben Okopnik [ben at linuxgazette.net]
On Tue, Jul 22, 2008 at 04:28:11AM -0700, Smile Maker wrote:
> Folks: > > When you do scp to remote machine, linux assumes to overwrite the > target file if exists.Is there any way to check whether the target file > exists and then copy the actual file.
You could use 'ssh' as a pipe instead of 'scp' (which does not provide the functionality you're looking for, as far as I know.) Untested:
tar czf - file1 file2 file3 ... | ssh user@host '(cd /my/target/dir; tar xvkzf -)'
The '-k' option to 'tar' on the receiver side "k"eeps the old files instead of overwriting them.
-- * Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *