Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

src and tgt are the locations that you want to keep synced. The rule is that tgt will be made to look like src. There are several options. First, you can just use short names. For example,

Code Block

rsync a b

will sync object a to object b where both a and b are in your current working directory. By object, it is meant either a file or a directory. For example,

Code Block

rsync a b

will sync a to b. If a, and b are both files, then b is updated to look like a. If b is a directory, then b/a is updated to look like a. Keep in mind that "update" means "created" if it doesn't exist. If a is a directory, then rsync will fail because, by default, rsync will not transfer directories. You can get around this by using the -a option. In other words,

Code Block

rsync -a a b

will transfer the directory a to become b. Typically, you will almost always be using -a, since it sets a number of other options which are used to help rsync mirror sets of files between two locations. With this use of rsync b/a is created or updated. If you use a/ as a source, then the contents of a are placed in b. You can also use the trailing slash with a target. For example, if a is a file, and you run

Code Block

rsync -a a b

then either b (if it is a file), or b/a (if it is a directory) is updated. In the case that you want to guard against typos overwriting a file, you can use b/. Then if what you type is not a directory, rsync will refuse to transfer the file. To sum up

object meaning
a b sync object (file or directory) a to (file or directory b)
a/ b sync contents of directory a to b
a b/ sync a to directory b
a/ b/ sync directory a/ to b/

As before either a or b can be a short name which means it refers to something in your current working directory, or it can

Syncing to a Remote/Host

Until now we've just assumed that we are syncing files in the same directory. However, rsync will also sync files between directories. For example, if you have modified files in your home directory, you might want to make sure the changed files are in your personal directory in your lab folder. In this case you could run,

...