Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Then you should use the -a option instead of -r (a is for archive, r is for recursive). So what you write is:
Code:
rsync -a local_dir user@othercomputer:dir_on_other_machine
rsync -a user@othercomputer:dir_on_other_machine local_dir
also, beware of appending a slash to your 'from folder'. Its hard to explain the difference, but if you try to sync a folder with and without the slash, I think you'll get it.
EDIT:
You might wanna add the -u option as well, so that it doesn't copy files that have a newer modified time in the 'to directory'. Depends how you're going to use it I guess.
Last edited by tom4everitt; 12-26-2009 at 03:04 AM.
There is no a better or worse solution for us. It all depends on what do you want to achieve. If you want to have an exact copy of your original directory, including permissions, ownership, modification times and so on... you need the -a archive option. If you want to add verbosity use the -v option. If you want to compress data during the transfer use -z.
Read carefully the rsync help or the manual page: then you will be aware that -a equals to -rlptgoD and that you can avoid some redundancy in your command line options.
also, beware of appending a slash to your 'from folder'. Its hard to explain the difference, but if you try to sync a folder with and without the slash, I think you'll get it.
I don't know what u exactly mean.
Can u pls give some more details and an example?
I don't know what u exactly mean.
Can u pls give some more details and an example?
THX
Okay, let me try to explain it then :P
If you have a folder foo containing files a1, a2, a3, that you want to copy to another folder bar, then if you do:
rsync -r foo/ bar
bar will end up containing a1, a2, a3.
If you instead do:
rsync -r foo bar
bar will end up containing a folder named foo which in turn contains a1, a2, a3.
So appending a / or not too foo makes quite a difference. As long as you stick to one of the options you'll be quite safe, but it's important to know there's a difference (the cp command does not care about an appended slash).
It all depends on whether you want to put the source folder INSIDE the target folder, or put its CONTENTS inside the target folder. The traditional Unix logic used on the "cp" command depends on whether the target folder already exists or not.
The simple command "cp -r foo bar" (assuming "foo" exists and is a directory) will behave differently if "bar" does not exist, than if "bar" does exist (and is a directory). This behavior can be changed by appending "/." to the source directory. The effect of doing that is that you are changing the final name component of the source directory from "foo" to ".". It is that last name component that is the target inside "bar". But since "." names the directory it is in, the effect is that the source and target are peers and the source contents become the target contents.
The "rsync" command changes this somewhat by allowing appending just "/" (though "/." also works) to have the effect of making the source and target directories be peers.
You have to decide whether you want the source directory to be put INSIDE the target directory, or to just merge the source directory contents into the target directory contents. You must make this decision if the target exists. If the target does not exist, then it will always make the target as an equivalent to the source. You append the "/" or "/." or not, as appropriate. I always recommend using "/." instead of "/" in the case where appending them is desired, since "/." works on other commands like "cp", too (e.g. you only have to remember to append "/." for whatever command is used for copying).
It all depends on whether you want to put the source folder INSIDE the target folder, or put its CONTENTS inside the target folder. The traditional Unix logic used on the "cp" command depends on whether the target folder already exists or not.
The simple command "cp -r foo bar" (assuming "foo" exists and is a directory) will behave differently if "bar" does not exist, than if "bar" does exist (and is a directory). This behavior can be changed by appending "/." to the source directory. The effect of doing that is that you are changing the final name component of the source directory from "foo" to ".". It is that last name component that is the target inside "bar". But since "." names the directory it is in, the effect is that the source and target are peers and the source contents become the target contents.
.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.