Why add a trailing slash after an rsync destination?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
8
down vote

favorite
1












According to this web page, adding '/' to the end of an rsync destination produces a different result from not adding it.



I've tried to test this, but I cannot verify it:



$ mkdir dir1..3
$ touch dir1/file
$ rsync -r dir1/ dir2
$ rsync -r dir1/ dir3/
$ ls dir*
dir1:
file

dir2:
file

dir3:
file


Does appending a '/' to the destination actually have a use sometimes?







share|improve this question




















  • Are you referring to this part of the man page: A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination.? If so please note how your command is not at all similar to the one in the example given in the man page.
    – Jesse_b
    Nov 4 '17 at 22:05










  • @Jesse_b Your comment does surprise me... "When using "/" at the end of destination, rsync will paste the data inside the last folder. When not using "/" at the end of destination, rsync will create a folder with the last destination folder name and paste the data inside that folder."
    – Hauke Laging
    Nov 4 '17 at 22:10










  • @HaukeLaging I'm confused, what is surprising? This particular section also refers to the trailing slash being on the source. So if you did rsync -r dir1/subdir1 dir2/ it will copy the contents of subdir1 into dir2 but if you did rsync -r dir1/subdir1/ dir2/ it will copy the whole directory (including contents) subdir1 into dir2 so you would have ./dir2/subdir1/
    – Jesse_b
    Nov 4 '17 at 22:15











  • @Jesse_b I did not notice the "man" in your first comment. Quite obviously the OP does not refer to the man page but to the page which he has linked.
    – Hauke Laging
    Nov 4 '17 at 22:32










  • @HaukeLaging Oh duh, didn't even see that. I think I was skimming too fast and read it as "According to the man page".
    – Jesse_b
    Nov 4 '17 at 22:33














up vote
8
down vote

favorite
1












According to this web page, adding '/' to the end of an rsync destination produces a different result from not adding it.



I've tried to test this, but I cannot verify it:



$ mkdir dir1..3
$ touch dir1/file
$ rsync -r dir1/ dir2
$ rsync -r dir1/ dir3/
$ ls dir*
dir1:
file

dir2:
file

dir3:
file


Does appending a '/' to the destination actually have a use sometimes?







share|improve this question




















  • Are you referring to this part of the man page: A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination.? If so please note how your command is not at all similar to the one in the example given in the man page.
    – Jesse_b
    Nov 4 '17 at 22:05










  • @Jesse_b Your comment does surprise me... "When using "/" at the end of destination, rsync will paste the data inside the last folder. When not using "/" at the end of destination, rsync will create a folder with the last destination folder name and paste the data inside that folder."
    – Hauke Laging
    Nov 4 '17 at 22:10










  • @HaukeLaging I'm confused, what is surprising? This particular section also refers to the trailing slash being on the source. So if you did rsync -r dir1/subdir1 dir2/ it will copy the contents of subdir1 into dir2 but if you did rsync -r dir1/subdir1/ dir2/ it will copy the whole directory (including contents) subdir1 into dir2 so you would have ./dir2/subdir1/
    – Jesse_b
    Nov 4 '17 at 22:15











  • @Jesse_b I did not notice the "man" in your first comment. Quite obviously the OP does not refer to the man page but to the page which he has linked.
    – Hauke Laging
    Nov 4 '17 at 22:32










  • @HaukeLaging Oh duh, didn't even see that. I think I was skimming too fast and read it as "According to the man page".
    – Jesse_b
    Nov 4 '17 at 22:33












up vote
8
down vote

favorite
1









up vote
8
down vote

favorite
1






1





According to this web page, adding '/' to the end of an rsync destination produces a different result from not adding it.



I've tried to test this, but I cannot verify it:



$ mkdir dir1..3
$ touch dir1/file
$ rsync -r dir1/ dir2
$ rsync -r dir1/ dir3/
$ ls dir*
dir1:
file

dir2:
file

dir3:
file


Does appending a '/' to the destination actually have a use sometimes?







share|improve this question












According to this web page, adding '/' to the end of an rsync destination produces a different result from not adding it.



I've tried to test this, but I cannot verify it:



$ mkdir dir1..3
$ touch dir1/file
$ rsync -r dir1/ dir2
$ rsync -r dir1/ dir3/
$ ls dir*
dir1:
file

dir2:
file

dir3:
file


Does appending a '/' to the destination actually have a use sometimes?









share|improve this question











share|improve this question




share|improve this question










asked Nov 4 '17 at 21:57









EmmaV

9891028




9891028











  • Are you referring to this part of the man page: A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination.? If so please note how your command is not at all similar to the one in the example given in the man page.
    – Jesse_b
    Nov 4 '17 at 22:05










  • @Jesse_b Your comment does surprise me... "When using "/" at the end of destination, rsync will paste the data inside the last folder. When not using "/" at the end of destination, rsync will create a folder with the last destination folder name and paste the data inside that folder."
    – Hauke Laging
    Nov 4 '17 at 22:10










  • @HaukeLaging I'm confused, what is surprising? This particular section also refers to the trailing slash being on the source. So if you did rsync -r dir1/subdir1 dir2/ it will copy the contents of subdir1 into dir2 but if you did rsync -r dir1/subdir1/ dir2/ it will copy the whole directory (including contents) subdir1 into dir2 so you would have ./dir2/subdir1/
    – Jesse_b
    Nov 4 '17 at 22:15











  • @Jesse_b I did not notice the "man" in your first comment. Quite obviously the OP does not refer to the man page but to the page which he has linked.
    – Hauke Laging
    Nov 4 '17 at 22:32










  • @HaukeLaging Oh duh, didn't even see that. I think I was skimming too fast and read it as "According to the man page".
    – Jesse_b
    Nov 4 '17 at 22:33
















  • Are you referring to this part of the man page: A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination.? If so please note how your command is not at all similar to the one in the example given in the man page.
    – Jesse_b
    Nov 4 '17 at 22:05










  • @Jesse_b Your comment does surprise me... "When using "/" at the end of destination, rsync will paste the data inside the last folder. When not using "/" at the end of destination, rsync will create a folder with the last destination folder name and paste the data inside that folder."
    – Hauke Laging
    Nov 4 '17 at 22:10










  • @HaukeLaging I'm confused, what is surprising? This particular section also refers to the trailing slash being on the source. So if you did rsync -r dir1/subdir1 dir2/ it will copy the contents of subdir1 into dir2 but if you did rsync -r dir1/subdir1/ dir2/ it will copy the whole directory (including contents) subdir1 into dir2 so you would have ./dir2/subdir1/
    – Jesse_b
    Nov 4 '17 at 22:15











  • @Jesse_b I did not notice the "man" in your first comment. Quite obviously the OP does not refer to the man page but to the page which he has linked.
    – Hauke Laging
    Nov 4 '17 at 22:32










  • @HaukeLaging Oh duh, didn't even see that. I think I was skimming too fast and read it as "According to the man page".
    – Jesse_b
    Nov 4 '17 at 22:33















Are you referring to this part of the man page: A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination.? If so please note how your command is not at all similar to the one in the example given in the man page.
– Jesse_b
Nov 4 '17 at 22:05




Are you referring to this part of the man page: A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination.? If so please note how your command is not at all similar to the one in the example given in the man page.
– Jesse_b
Nov 4 '17 at 22:05












@Jesse_b Your comment does surprise me... "When using "/" at the end of destination, rsync will paste the data inside the last folder. When not using "/" at the end of destination, rsync will create a folder with the last destination folder name and paste the data inside that folder."
– Hauke Laging
Nov 4 '17 at 22:10




@Jesse_b Your comment does surprise me... "When using "/" at the end of destination, rsync will paste the data inside the last folder. When not using "/" at the end of destination, rsync will create a folder with the last destination folder name and paste the data inside that folder."
– Hauke Laging
Nov 4 '17 at 22:10












@HaukeLaging I'm confused, what is surprising? This particular section also refers to the trailing slash being on the source. So if you did rsync -r dir1/subdir1 dir2/ it will copy the contents of subdir1 into dir2 but if you did rsync -r dir1/subdir1/ dir2/ it will copy the whole directory (including contents) subdir1 into dir2 so you would have ./dir2/subdir1/
– Jesse_b
Nov 4 '17 at 22:15





@HaukeLaging I'm confused, what is surprising? This particular section also refers to the trailing slash being on the source. So if you did rsync -r dir1/subdir1 dir2/ it will copy the contents of subdir1 into dir2 but if you did rsync -r dir1/subdir1/ dir2/ it will copy the whole directory (including contents) subdir1 into dir2 so you would have ./dir2/subdir1/
– Jesse_b
Nov 4 '17 at 22:15













@Jesse_b I did not notice the "man" in your first comment. Quite obviously the OP does not refer to the man page but to the page which he has linked.
– Hauke Laging
Nov 4 '17 at 22:32




@Jesse_b I did not notice the "man" in your first comment. Quite obviously the OP does not refer to the man page but to the page which he has linked.
– Hauke Laging
Nov 4 '17 at 22:32












@HaukeLaging Oh duh, didn't even see that. I think I was skimming too fast and read it as "According to the man page".
– Jesse_b
Nov 4 '17 at 22:33




@HaukeLaging Oh duh, didn't even see that. I think I was skimming too fast and read it as "According to the man page".
– Jesse_b
Nov 4 '17 at 22:33










1 Answer
1






active

oldest

votes

















up vote
19
down vote



accepted










It does make a difference when the source is a file and the destination directory does not exist. For instance take a file called file as source:




  • $ rsync file dest/ will create a copy of file inside a directory dest, whereas


  • $ rsync file dest will make a copy of the file file called dest


To add (from the comments); if a directory dest already exists, a copy file will be created in dest in both cases above.



Basic example:



~/test > touch file
~/test > mkdir dest1
mkdir: created directory 'dest1'
~/test > tree
.
├── dest1
└── file

1 directory, 1 file
~/test > rsync file dest1
~/test > rsync file dest2
~/test > rsync file dest3/
~/test > tree
.
├── dest1
│   └── file
├── dest2
├── dest3
│   └── file
└── file

2 directories, 4 files
~/test >





share|improve this answer






















  • Thank you. So if directory dest already exists, there's no need for the trailing slash?
    – EmmaV
    Nov 4 '17 at 22:16










  • Exactly. If in the example above a directory dest exists, a copy of file will be created inside in both cases.
    – resc
    Nov 4 '17 at 22:20











  • This was the clearest answer I could follow (being a newbie :-). Thanks +1
    – beeshyams
    Jun 30 at 15:06










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f402555%2fwhy-add-a-trailing-slash-after-an-rsync-destination%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
19
down vote



accepted










It does make a difference when the source is a file and the destination directory does not exist. For instance take a file called file as source:




  • $ rsync file dest/ will create a copy of file inside a directory dest, whereas


  • $ rsync file dest will make a copy of the file file called dest


To add (from the comments); if a directory dest already exists, a copy file will be created in dest in both cases above.



Basic example:



~/test > touch file
~/test > mkdir dest1
mkdir: created directory 'dest1'
~/test > tree
.
├── dest1
└── file

1 directory, 1 file
~/test > rsync file dest1
~/test > rsync file dest2
~/test > rsync file dest3/
~/test > tree
.
├── dest1
│   └── file
├── dest2
├── dest3
│   └── file
└── file

2 directories, 4 files
~/test >





share|improve this answer






















  • Thank you. So if directory dest already exists, there's no need for the trailing slash?
    – EmmaV
    Nov 4 '17 at 22:16










  • Exactly. If in the example above a directory dest exists, a copy of file will be created inside in both cases.
    – resc
    Nov 4 '17 at 22:20











  • This was the clearest answer I could follow (being a newbie :-). Thanks +1
    – beeshyams
    Jun 30 at 15:06














up vote
19
down vote



accepted










It does make a difference when the source is a file and the destination directory does not exist. For instance take a file called file as source:




  • $ rsync file dest/ will create a copy of file inside a directory dest, whereas


  • $ rsync file dest will make a copy of the file file called dest


To add (from the comments); if a directory dest already exists, a copy file will be created in dest in both cases above.



Basic example:



~/test > touch file
~/test > mkdir dest1
mkdir: created directory 'dest1'
~/test > tree
.
├── dest1
└── file

1 directory, 1 file
~/test > rsync file dest1
~/test > rsync file dest2
~/test > rsync file dest3/
~/test > tree
.
├── dest1
│   └── file
├── dest2
├── dest3
│   └── file
└── file

2 directories, 4 files
~/test >





share|improve this answer






















  • Thank you. So if directory dest already exists, there's no need for the trailing slash?
    – EmmaV
    Nov 4 '17 at 22:16










  • Exactly. If in the example above a directory dest exists, a copy of file will be created inside in both cases.
    – resc
    Nov 4 '17 at 22:20











  • This was the clearest answer I could follow (being a newbie :-). Thanks +1
    – beeshyams
    Jun 30 at 15:06












up vote
19
down vote



accepted







up vote
19
down vote



accepted






It does make a difference when the source is a file and the destination directory does not exist. For instance take a file called file as source:




  • $ rsync file dest/ will create a copy of file inside a directory dest, whereas


  • $ rsync file dest will make a copy of the file file called dest


To add (from the comments); if a directory dest already exists, a copy file will be created in dest in both cases above.



Basic example:



~/test > touch file
~/test > mkdir dest1
mkdir: created directory 'dest1'
~/test > tree
.
├── dest1
└── file

1 directory, 1 file
~/test > rsync file dest1
~/test > rsync file dest2
~/test > rsync file dest3/
~/test > tree
.
├── dest1
│   └── file
├── dest2
├── dest3
│   └── file
└── file

2 directories, 4 files
~/test >





share|improve this answer














It does make a difference when the source is a file and the destination directory does not exist. For instance take a file called file as source:




  • $ rsync file dest/ will create a copy of file inside a directory dest, whereas


  • $ rsync file dest will make a copy of the file file called dest


To add (from the comments); if a directory dest already exists, a copy file will be created in dest in both cases above.



Basic example:



~/test > touch file
~/test > mkdir dest1
mkdir: created directory 'dest1'
~/test > tree
.
├── dest1
└── file

1 directory, 1 file
~/test > rsync file dest1
~/test > rsync file dest2
~/test > rsync file dest3/
~/test > tree
.
├── dest1
│   └── file
├── dest2
├── dest3
│   └── file
└── file

2 directories, 4 files
~/test >






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 4 '17 at 22:29

























answered Nov 4 '17 at 22:10









resc

827315




827315











  • Thank you. So if directory dest already exists, there's no need for the trailing slash?
    – EmmaV
    Nov 4 '17 at 22:16










  • Exactly. If in the example above a directory dest exists, a copy of file will be created inside in both cases.
    – resc
    Nov 4 '17 at 22:20











  • This was the clearest answer I could follow (being a newbie :-). Thanks +1
    – beeshyams
    Jun 30 at 15:06
















  • Thank you. So if directory dest already exists, there's no need for the trailing slash?
    – EmmaV
    Nov 4 '17 at 22:16










  • Exactly. If in the example above a directory dest exists, a copy of file will be created inside in both cases.
    – resc
    Nov 4 '17 at 22:20











  • This was the clearest answer I could follow (being a newbie :-). Thanks +1
    – beeshyams
    Jun 30 at 15:06















Thank you. So if directory dest already exists, there's no need for the trailing slash?
– EmmaV
Nov 4 '17 at 22:16




Thank you. So if directory dest already exists, there's no need for the trailing slash?
– EmmaV
Nov 4 '17 at 22:16












Exactly. If in the example above a directory dest exists, a copy of file will be created inside in both cases.
– resc
Nov 4 '17 at 22:20





Exactly. If in the example above a directory dest exists, a copy of file will be created inside in both cases.
– resc
Nov 4 '17 at 22:20













This was the clearest answer I could follow (being a newbie :-). Thanks +1
– beeshyams
Jun 30 at 15:06




This was the clearest answer I could follow (being a newbie :-). Thanks +1
– beeshyams
Jun 30 at 15:06

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f402555%2fwhy-add-a-trailing-slash-after-an-rsync-destination%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay