network
rsync
Efficient file synchronizer that copies only the differences between source and destination. Works locally or over SSH.
rsync [OPTIONS] SRC... DEST Common flags
| Flag | Purpose |
|---|---|
| -a | Archive: recurse and preserve permissions, times, symlinks, ownership |
| -v | Verbose output |
| -z | Compress data during transfer |
| -P | Show progress and keep partially transferred files |
| --delete | Delete files in DEST that no longer exist in SRC |
| --exclude | Skip paths matching PATTERN |
| -n | Dry run -- show what would change without doing it |
| -e | Specify the remote shell (e.g. -e 'ssh -p 2222') |
Examples
rsync -avP src/ backup/ Sync locally with progress; note the trailing slash on src/
rsync -avz --delete site/ user@host:/var/www/site/ Mirror a directory to a remote host and drop stale files
rsync -avn src/ backup/ Dry run to preview the sync
rsync -av --exclude='node_modules' proj/ user@host:/srv/proj/ Sync a project while skipping build junk
Gotcha
A trailing slash on the source (src/) copies its contents; without the slash (src) it copies the directory itself -- an easy way to nest an unintended level.
Related commands
ssh
Opens an encrypted shell session to a remote host. Also runs single remote commands and can tunnel arbitrary TCP ports.
cp
Copies files and directories from one location to another. Preserves or transforms metadata depending on flags.
curl
Transfers data to or from a server across many protocols including HTTP, HTTPS, FTP, and SCP. The Swiss Army knife of ad-hoc HTTP requests.
dig
Queries DNS servers for records and diagnostics. Preferred over nslookup for scripting and detailed troubleshooting.