Optimize for happiness

Life is easier with simple scripting. Grateful for everyone's encouragement and support!

View this project on GitHub

Rsync for making copies (command line)

2023.06.09   •   last modified 2023.06.29   •   2 min read

There are so many uses and options with rsync, it’s mind-boggling. After some searching and manual reading, I arrived at a command that I use.

So many times I want to keep an extra copy of some important files on a couple of external drives. Here is a command I arrived at:

rsync -avhWxS --no-compress --progress --info=progress2 <input file> <output directory>
  # rsync  version 3.2.7  protocol version 31
  # additional option that is sometimes needed:
  # --delete-after

Options used:

  • -a archive
  • -v verbose (I prefer more info displayed)
  • -h human readable file sizes
  • -W copy files whole
  • -x don’t cross filesystem boundaries
  • -S turn sequences of nulls into sparse blocks
  • --no-compress no need for compression for local transfers
  • --progress --info=progress2 shows copy progress - may need an update from the old standard rsync version
  • the danger option: --delete-after delete extraneous files from the destination after the transfer of the new files (not during)

The above command became two aliases in my ~/.zshrc file (or your shell file):

alias rsync-my="rsync -avhWxS --no-compress --progress --info=progress2"
alias rsync-my-delete="rsync -avhWxS --no-compress --progress --info=progress2 --delete-after"

Currently, Mac OS 13 ships with a very old version 2 of rsync. To get the beautiful copy progress for each file, I decided to upgrade rsync to the latest version 3 at the time. Instructions on rsync installation are on the main rsync site. There is one other major benefit for upgrading from version 2: improved memory usage.

Note: this command is finicky with slashes at the end of source and destination directories to make sure to test it out with no deleting to see where the source files (or directories) are being sent. A "control - c" shortcut can exit the command if the files are not being put where you intended. Then, remove or add the “/” after the destination folder if the copy is one directory level off. I admit, with rsync, that has happened to me and so I learned.

Say Hi!