Making rsync easy
rsync is an invaluable tool for copying or uploading files. From the manual:
It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. … It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.
It’s incredibly useful, but it can be rather daunting to use for simple tasks, due to the overwhelming number of options available. Because of this, I have written a general purpose alias for bash that takes the effort out of most rsync jobs.
Add this to your .bashrc file:
alias scpr='rsync -Phavze ssh --modify-window=1'
This will give you a simple rsync source/ destination/ command, which will copy everything from source to destination. No need to worry about which files have already been copied; rsync will only change what’s needed.
For example, the following command might be used to update a user’s website:
$ scpr ~/Sites/"my awesome website"/ user@host:www/
The --delete option can be added to remove files at the destination that do not exist at the source. The command scpr --delete x/ y/ essentially means “make y an exact copy of x”. Use with care!
(Note: Omitting the trailing slash from the source folder alters the behaviour of rsync. See the ‘USAGE’ section in the rsync manual. If you’re unsure, just leave it in.)