assume
/home/test/user1/foo /var/www/html
a user is in the "/" dir
how can this user copy/rsync "foo" dir to get /var/www/html/foo
i know you could cd to /home/test/user1 and do rsync -vv -aR foo/ /var/www/html/
which would get /var/www/html/foo
but doing an rsync to a specific target dir.. not sure about how to do this! i know it's a basic question.. but I'm missing it. (google hasn't helped)
thoughts/comments
thanks
Hi.
On Sun, 12 Jul 2020 16:06:00 -0400 bruce wrote:
assume
/home/test/user1/foo /var/www/html
a user is in the "/" dir
how can this user copy/rsync "foo" dir to get /var/www/html/foo
i know you could cd to /home/test/user1 and do rsync -vv -aR foo/ /var/www/html/
Simply do, from / or anywhere:
rsync -vv -a /home/test/user1/foo /var/www/html/
or:
rsync -vv -a /home/test/user1/foo/ /var/www/html/foo
rsync accept to create one level of directory on the destination.
On 12Jul2020 16:06, bruce badouglas@gmail.com wrote:
assume
/home/test/user1/foo /var/www/html
a user is in the "/" dir
how can this user copy/rsync "foo" dir to get /var/www/html/foo
i know you could cd to /home/test/user1 and do rsync -vv -aR foo/ /var/www/html/
which would get /var/www/html/foo
Actually, no. That would put "foo/A" at "html/A", not at "html/foo/A".
The above command makes the 2 directories '..../foo/' and '..../html/' the same. If you remove the trailing '/' from the source:
rsync -vv -aR foo /var/www/html/
That causes rsync to create a "foo" _inside_ the "html/" directory.
The easy habit is this pair:
Make two directories the same:
rsync path/to/A/ other/path/to/B/
(no bare names after the final '/').
Make "A" inside "B":
rsync path/to/A other/path/to/B/
(a bare name in the source, trailing / in the target).
In general, rsync behaves like cp, ln, mv in that if the target is an existing directoy it puts the source _inside_ it. So
rsync path/to/A other/path/to/B
makes an "other/path/to/B/A" _if_ "B" already exists. If it doesn't, it makes "B" like "A" because there's no preexisting directory.
I find it safer, usually, to make the target first ("mkdir other/path/to/B") and use the earlier form:
rsync path/to/A/ other/path/to/B/
It never wants to make a new subdirectory, and fails if "B" does no exist. Safer and more predictable all around.
Cheers, Cameron Simpson cs@cskk.id.au
On Mon, 2020-07-13 at 19:20 +1000, Cameron Simpson wrote:
Make two directories the same:
rsync path/to/A/ other/path/to/B/(no bare names after the final '/').
I don't think the trailing slash matters on the destination directory. At least that's not what the man page seems to say (and none of the examples there use a trailing slash on a destination).
poc
On 13Jul2020 11:25, Patrick O'Callaghan pocallaghan@gmail.com wrote:
On Mon, 2020-07-13 at 19:20 +1000, Cameron Simpson wrote:
Make two directories the same:
rsync path/to/A/ other/path/to/B/(no bare names after the final '/').
I don't think the trailing slash matters on the destination directory. At least that's not what the man page seems to say (and none of the examples there use a trailing slash on a destination).
That is... interesting.
I expected, and I had thought years of personal rsync usage had bourne this out, that if there was no B directory, then
rsync -ia A B
would make a "B" the same shape as "A". Like "cp -a A B", when B does not exist.
But it doesn't, it creates B and puts an "A" inside it.
Still this makes an unwanted subdirectory (unwanted to me, most of the time). I still prefer the both-src-and-dst-exist approach an to use a trailing slash:
rsync -ia A/ B/
which just replicates the contents of A inside B.
So I almost always want to go "make these 2 things the same", not "make a copy of this _inside_ that".
Cheers, Cameron Simpson cs@cskk.id.au
On Mon, 2020-07-13 at 20:39 +1000, Cameron Simpson wrote:
Still this makes an unwanted subdirectory (unwanted to me, most of the
time). I still prefer the both-src-and-dst-exist approach an to use a
trailing slash:
rsync -ia A/ B/which just replicates the contents of A inside B.
My point is that leaving out the trailing slash on B makes absolutely no difference to what happens.
poc
On Mon, Jul 13, 2020 at 12:26 PM Patrick O'Callaghan pocallaghan@gmail.com wrote:
On Mon, 2020-07-13 at 19:20 +1000, Cameron Simpson wrote:
Make two directories the same:
rsync path/to/A/ other/path/to/B/
(no bare names after the final '/').
I don't think the trailing slash matters on the destination directory.
+1
The trailing slash only matters for the source directory.
I think of the trailing slash for "cp" on *BSD (and macOS) and "rsync" as meaning "/*"...
On Mon, 2020-07-13 at 16:37 +0200, Tom H wrote:
The trailing slash only matters for the source directory.
I think of the trailing slash for "cp" on *BSD (and macOS) and "rsync" as meaning "/*"...
Does it matter anywhere? I've always put one on the end of directory filepaths, just for my own clarity, unless something explicitly tells me not to. I can vaguely remember some info about not doing it somewhere in Apache configurations, but that's all.
On Tue, 2020-07-14 at 03:20 +0930, Tim via users wrote:
On Mon, 2020-07-13 at 16:37 +0200, Tom H wrote:
The trailing slash only matters for the source directory.
I think of the trailing slash for "cp" on *BSD (and macOS) and "rsync" as meaning "/*"...
Does it matter anywhere? I've always put one on the end of directory filepaths, just for my own clarity, unless something explicitly tells me not to. I can vaguely remember some info about not doing it somewhere in Apache configurations, but that's all.
It does matter for source directories when using rsync. The rsync man page is quite explicit about it. This is specific (and non-standard) for rsync, not a general rule for file-system semantics.
poc
On Mon, Jul 13, 2020 at 7:51 PM Tim via users users@lists.fedoraproject.org wrote:
On Mon, 2020-07-13 at 16:37 +0200, Tom H wrote:
The trailing slash only matters for the source directory.
I think of the trailing slash for "cp" on *BSD (and macOS) and "rsync" as meaning "/*"...
Does it matter anywhere? I've always put one on the end of directory filepaths, just for my own clarity, unless something explicitly tells me not to. I can vaguely remember some info about not doing it somewhere in Apache configurations, but that's all.
It matters for rsync.
If you have /path/to/a/fed.txt
rsync -a /path/to/a /path/to/b results in /path/to/b/a/fed.txt
rsync -a /path/to/a/ /path/to/b results in /path/to/b/fed.txt
Hi
Another rather recent feature of "rsync -R" (--relative) is to easily allow to specify from what point you want -R to apply.
From the man:
-R, --relative ... It is also possible to limit the amount of path information that is sent as implied directories for each path you specify. With a modern rsync on the sending side (beginning with 2.6.7), you can insert a dot and a slash into the source path, like this:
rsync -avR /foo/./bar/baz.c remote:/tmp/
That would create /tmp/bar/baz.c on the remote machine. (Note that the dot must be followed by a slash, so "/foo/." would not be abbreviated.) For older rsync versions, you would need to use a chdir to limit the source path. For example, when pushing files:
(cd /foo; rsync -avR bar/baz.c remote:/tmp/)