News for hackers. Stuff that matters.
Re:Deprecating scp by mhalle on Friday November 06, 2020 @05:50AM (#25006665)
Rsync has "weird" syntax for a reason. Unlike other unix-like commands, it treats trailing slashes as significant. If a directory has a trailing slash, it means "contents" of the directory". No slash means "the directory itself". These are two different concepts, and a program that copies directories should take the difference into account.

scp (and cp, for that matter) don't take this difference into account. That leads to gotchas with recursive (-r) copying. Most importantly, scp isn't idemopotent:

scp -r fromdir todir

If todir doesn't exist, scp will copy the contents of directory fromdir to a new directory named todir.

Execute the same command again (now that todir exists), and scp will copy fromdir to todir/fromdir .

On the other hand:

rsync -a fromdir/ todir

will always copy the contents of fromdir into a directory named todir (effectively, a directory rename operation), whether todir exists or not.

rsync -a fromdir todir

will always copy the directory fromdir into the directory todir, whether todir exists or not.

These rsync operations are idempotent, which it important because rsync is designed to incrementally re-sync directories. It is expected that it will commonly be run more than once, which is why it needed to address this IMHO fundamental bug/limitation in cp and scp.

Re:Deprecating scp by orra on Friday November 06, 2020 @07:15AM (#25007064)
Ah, good explanation. Rsync's command line syntax always felt more intuitive to me, and it being idempotent is part of that.
Re:Deprecating scp by WanderPanda on Friday November 06, 2020 @05:57AM (#25006695)
Thanks for the concise clarification! I always was too lazy to think and did trial and error until it did the thing I intended :)
Re:Deprecating scp by Buttons840 on Friday November 06, 2020 @06:14AM (#25006785)
What does rsync'ing "the directory itself" (in contrast to the directory content) even do? A mkdir? Does it even need to use the network connection?
Re:Deprecating scp by mhalle on Friday November 06, 2020 @08:40AM (#25007512)
"Rsyncing the directory itself" means making a copy of the directory node (the root of the tree) and naming it with the original name in the new location. That is different than taking the children of the source directory and copying them into the new location.

Scp and cp have the same semantics, so cp is vulberable to this gotcha as well. Rsync doesn't have to be used with remote sources or targets (nor does scp).

Re:Deprecating scp by Izkata on Friday November 06, 2020 @09:36AM (#25007841)
> so cp is vulberable to this gotcha as well

This is in fact why use rsync for local copies as well, it's much more consistent.

Re:Deprecating scp by 411111111111111 on Friday November 06, 2020 @06:57AM (#25006982)
Rsync only works on directories in recursive mode which also copies the contents