rsync cheat sheet

Things I use rsync for:

rsync is a good program for these tasks because it will only copy the file if it changed.

Connecting to servers is done with ssh. If you can ssh user@server you can rsync user@server:/some/path.

flags

the -a flag is “archive mode”, which enables all of -rlptgoD:

Some of this is overkill unless you’re doing “backups”; and copying from one computer to another can result in nonsense group/ownership information if the computers don’t have their groups and users set up exactly the same way.

trailing slashes

let’s say we have a file at /path/to/source/hello.txt

A trailing slash on the source is usually what you want. No-trailing-slash is more like “dragging-and-dropping source into dest using a graphical file manager.”

trailing slash on the destination

For completeness, even though this only makes a difference iff the source is a file and the dest doesn’t exist, which is kind of a weird way to use rsync:

i.e.

cp would error in the first case (copying to a trailing-slashed path). rsync is implementing a “do what i mean” behavior here

Termux

Copying from Termux onto a normal computer is probably going to mangle the permission bits and owning group/user information on the destination. (Termux runs under some weird umasks, and rsync dutifully copies them.)

I work around this with an ssh dest_computer "chmod +rX -R /path/to/dest/; chown owning_user:owning_group -R /path/to/dest/" lmao, kind of a sledgehammer but it works.

TODO: Maybe rsync --super will also help (“This tells the receiving side to attempt super-user activities even if the receiving rsync wasn’t run by the super-user”)