Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to scp while maintaining symbolic links?

15,678 views
Skip to first unread message

Peng Yu

unread,
Nov 13, 2009, 10:36:16 AM11/13/09
to
I'm going to copy a directory. There are symbolic links pointing to
files in the same directory. I'm wondering if there is a way to
maintain symbolic links.

Unruh

unread,
Nov 13, 2009, 11:53:40 AM11/13/09
to
Peng Yu <peng...@gmail.com> writes:

Use rsync.
rsync -av path/to/olddirectory/ path/to/newdirectory
(If you want the directory olddirectory to be withing newdirectory, not just the
contents do
rsync -av path/to/olddirectory path/to/newdirectory
note the absence of that trailing slash.
)

Nico Kadel-Garcia

unread,
Nov 13, 2009, 10:41:26 PM11/13/09
to
On Nov 13, 11:53 am, Unruh <unruh-s...@physics.ubc.ca> wrote:

This is comp.security.ssh: let's assume one end or the other is SSH
connected, that rsync is installed on both ends, that you want to
preserve hard links, and that you want to actually synchronize them
and delete anything that doesn't exist on the source side. You may
prefer this:

rsync -avH --delete remotehost:/srcdir/ /localdir/

Note the use of -a, -v for verboe, -H for hardlinks, and --delete for
flushing non-present files. Also note the trailing slashes to make
that the contents of the directories match precisely and you don't
create extraneous subdirectories.

Unruh

unread,
Nov 14, 2009, 12:05:23 AM11/14/09
to
Nico Kadel-Garcia <nka...@gmail.com> writes:

>On Nov 13, 11:53=A0am, Unruh <unruh-s...@physics.ubc.ca> wrote:
>> Peng Yu <pengyu...@gmail.com> writes:
>> >I'm going to copy a directory. There are symbolic links pointing to
>> >files in the same directory. I'm wondering if there is a way to
>> >maintain symbolic links.
>>
>> Use rsync.
>> rsync -av path/to/olddirectory/ path/to/newdirectory

>> (If you want the directory olddirectory to be withing newdirectory, not j=


>ust the
>> contents do
>> rsync -av path/to/olddirectory path/to/newdirectory
>> note the absence of that trailing slash.
>> )

>This is comp.security.ssh: let's assume one end or the other is SSH

rsync uses ssh. Also he asks how to copy files. I am supposed to tell him to use
an inferior product to do what he asks for? :-)


>connected, that rsync is installed on both ends, that you want to
>preserve hard links, and that you want to actually synchronize them
>and delete anything that doesn't exist on the source side. You may
>prefer this:

> rsync -avH --delete remotehost:/srcdir/ /localdir/

Both rsync and scp can be used to copy files from the same machine. Admittedly it
is usually used remotely.
Why do you want to use --delete? That deletes all files in /localdir which are not
in /srcdir.


>Note the use of -a, -v for verboe, -H for hardlinks, and --delete for
>flushing non-present files. Also note the trailing slashes to make
>that the contents of the directories match precisely and you don't
>create extraneous subdirectories.

Only the first trailing slash is needed. the second one does not, as far as I can
see, do anything.

Nico Kadel-Garcia

unread,
Nov 14, 2009, 3:49:00 AM11/14/09
to

Right. That's why I *explained* its use. In many cases, you want to
mirror the contents of localdir of srcdir to localdir precisely. In
such a case, you want to use --delete. Also, if rsync gets
interrupted, it leaves behind some temporary files in the midst of
copying. /srcdir/filename/ would leave behind an in-progress
transmission file called /localdir/.filename.xyzqtf or something like
that.

> >Note the use of -a, -v for verboe,  -H for hardlinks, and --delete for
> >flushing non-present files. Also note the trailing slashes to make
> >that the contents of the directories match precisely and you don't
> >create extraneous subdirectories.
>
> Only the first trailing slash is needed. the second one does not, as far as I can
> see, do anything.

By being consistent about the use of the trailing slash for
directories, it makes the code more consistent and more legible. For
example, one can use the slash always for transmitting directories,
and leave it off for transmitting files or symlinks. And one can
reverse the command without having to keep track of which one has a
trailing slash and which doesn't.

0 new messages