Some Useful Real World rsync Commands

Rsync is something every linux user should learn and at least try to commit to memory.. It's come in handy to me over and over and today I find myself in yet another situation where I need rsync to save me a shit load of manual messing around.

Basic Syntax
rsync [options] source destination

Common Options:
- v = Be verbose (You knew that didn't you)
-r = Be recursive
-a = archive mode, preserves everything it can and allows recursive
-z = compress data
-h = Human readable output

I tend to use rsync in the same way every time so I don't have to reference the man page each time I use it. To that end:

Sync Remote Directory to Local:
rsync -avhz root@there:/path/to/files /local/path/to/files

Keep in mind the slashes matter. Adding slashes to the end changes the way rsync saves the files locally if you DON'T add slashes rsync will save the directory so in the above example rsync will create a directory in /local/path/to/files - if you add a slash to the end it will save to /local/path/to/files.. Works a bit like the * wildcard on file copies!

Bare in mind too, rsync uses SSH by default so you can use SSH keys to make life easier if you are doing a lot of work!

Show Progress:
rsync -avhz --progress root@there:/path/to/files /local/path/to/files

Including or Excluding:
rsync -avhz root@there:/path/to/files /local/path/to/files --exclude '*log' --include 'ROB'

This command will ignore or include anything that matches the wild cards! You can also delete the source file after use OR delete the destination file if it's gone from the source.

Deleting Destination Files:
rsync -avhz --delete root@there:/path/to/files /local/path/to/files

Deleting Source Files:
rsync -avhz --remove-source-files root@there:/path/to/files /local/path/to/files

As you can see, rsync is a great tool for file transfers. Remember, you can use it in exactly the same way to move files around locally!


iForgot

Every time I forget how to use this program and have to look in the manual!

----

Add Comment

Poster Name / Handle / Email:

Comment

Add the words "cat cant"


Back