Dec
6
A fantastic utility for copying files in a unix based environment is rsync. It will let you copy from one location to another or to another computer if need be. You can do a lot of things with rsync. But lets start out with the basics.
Copying locally:
rysnc is like most other copy utilities. You must specify a source and a destination. Here are some examples.
This will copy the entire /home directory to /backup. Notice there is no trailing slash on the source of /home. This tells rsync to transfer /home and all the contents within. If you included a trailing slash rsync would transfer all of the files within the home directory, but not home itself. This is an important point to keep in mind.
Now.. Say you need to restore a user’s public_html contents. The syntax would be as follows.
Okay now.. Getting the hang of it? Now for some really cool stuff!
Transferring to and from remote machines:
So, recently I got a new laptop and I wanted to copy my music collection over to it so I could have more to listen to at work. I used rsync over SSH to get this done. Now, generally you probably don’t want to have rsync open to the public if you want to maintain some privacy and security. That is why it is wise to use rsync over ssh. This sounds much more complicated than it actually is.
The only thing that you need to do is to add the -e flag to execute a command. So in this case, we use -e ssh to execute rsync over ssh. The way I have illustrated above will allow you to transfer from one machine to another without being logged into either of them. This is in my opinion one of the coolest things about rsync.
Flags:
Some of my favorite flags.
-a, –archive archive mode; same as -rlptgoD (no -H)
-v, –verbose increase verbosity
-e, –rsh=COMMAND specify the remote shell to use
-q, –quiet suppress non-error messages–progress show progress during transfer
–exclude=PATTERN exclude files matching PATTERN
Hopefully this is a good starter for all of you out there that aren’t that well versed with rsync. I find this utility being used more than twice in my every day computing life. Please post any questions in the comments.

December 6th, 2007 at 9:25 pm
“rsync -av /backup/home/user1/public_html/ /home/user1/public_html”
That command will come in handy, most definitely, as one of my friends asked me if it were possible to do something like this, now I know it is! Thank you for the information. Can’t wait to read the rest of your articles.