This is a card in Dave's Virtual Box of Cards.

rsync -a

Created: 2024-06-07

I find myself looking this up all the time. Rsync’s most popular invocation is:

rsync -av <source> <destination>

The -a stands for "archive" mode and -v is for verbose mode (otherwise rsync is silent, like a proper Unix utility).

But I always end up having to decode all of the implied options that -a entails.

From the man page:

-a, --archive    archive mode; equals -rlptgoD (no -H,-A,-X)

Which decodes to these features being turned on:

 -r, --recursive    recurse into directories
 -l, --links        copy symlinks as symlinks
 -p, --perms        preserve permissions
 -t, --times        preserve modification times
 -g, --group        preserve group
 -o, --owner        preserve owner (super-user only)
 -D                 same as --devices --specials

Basically: All files in the source path will being synced to the destination, preserving the typical file metadata such as file times, permissions, and ownership.

Additional explanation:

Symlinks are copied as links, that is, as tiny little paths rather than as copies of what is being linked (that’s also an option, of course, but not the default).

The -D option causes rsync to copy oddball filesystem items like devices, named sockets, etc. These aren’t likely to be in your documents directory. :-)

These advanced features are turned off:

 -H, --hard-links    preserve hard links
 -A, --acls          preserve ACLs (implies -p)
 -X, --xattrs        preserve extended attributes

Under --hard-links, the man page explains:

"This tells rsync to look for hard-linked files in the transfer and link together the corresponding files on the receiving side. Without this option, hard-linked files in the transfer are treated as though they were separate files."

I have very little personal experience with hard links and if you do need this feature turned on, you probably know what you’re doing.

ACLs are Access Control Lists and if you’re using them, you’re part of some big organization that needs them and you probably know what you’re doing.

Extended attributes (xattrs) are just like ACLs - if you’re using extended attributes on files in your filesystem, you probably know what you’re doing.