Skip to content

Instantly share code, notes, and snippets.

@InAnimaTe
Last active May 22, 2025 16:35
Show Gist options
  • Save InAnimaTe/79c7c394c759fcb53f5f68309deee7ab to your computer and use it in GitHub Desktop.
Save InAnimaTe/79c7c394c759fcb53f5f68309deee7ab to your computer and use it in GitHub Desktop.
Rsync Command Cheat Sheet

rsync --dry-run -ahviPHX /mnt/bar /mnt/foo/ explainshell

*This will result in bar existing in foo so you'd have /mnt/foo/bar/bar1.jpg

rsync --dry-run -ahviPHX /mnt/bar/* /mnt/foo/ explainshell

*This will result in solely the non-hidden contents of bar (bar/*) existing inside foo so you'd have /mnt/foo/bar1.jpg

Network Transfer Considerations (tailscale/sshfs/etc)

When using this to transfer over a network, consider using the following:

  • --delay-updates which will ensure your active usecases aren't seeing temp/stub files
  • --timeout=300 has rsync quit out if the connection is failing
  • When referencing a module + path, to copy the contents of the directory, verify you use <module-name>/<dir>/
  • To view modules or their contents, use rsync rsync://<hostname>/ or rsync <hostname>::, then build the path to view its contents.

Don't use compress! You don't need it and you'll incur extra cpu overhead which will impact performance

rsync --dry-run -ahviyHP --delete-delay --delay-updates --timeout=300 rsync://mirror.rit.edu/ubuntu-releases /mnt/isos/linux/ubuntu-releases explainshell

This will result in /mnt/isos/linux/ubuntu-releases receiving the contents (i.e. 24.10/, xenial/, etc.) of the module!

-a is the same as -rlptgoD

-P is --partial and --progress - just re-execute command if it times out!

Slashes and Wildcards Matter when defining the Source!

  • /source/* (Preferred!) → only the non-hidden contents of the folder are copied
  • /source/{*,.[!.]*,..?*} → all contents, including hidden, of the folder are copied
  • /source/ → contents of the folder are copied, including the timestamp and permissions of the encasing folder source to the destination containing folder destination/
  • /source → folder itself is copied into destination

This is different with referencing a rsync module! It will always sync the contents of the module, not the module name as a directory.

Example
rsync -a /mnt/usb1/data/ /mnt/pool/backup/     # Copies contents
rsync -a /mnt/usb1/data  /mnt/pool/backup/     # Creates /backup/data/

Bandwidth Limit in kbps

--bwlimit=25600 # ~ 25MBps

Any matches glob

--exclude='*live*'

Specific path

--exclude='somefolder/README.txt'

Specific top Directory

--exclude='temp/'

Exclude everything under a path (incl subdirs)

--exclude='temp/**'

Exclude all "thumbnails" directories matching anywhere

--exclude='*/thumbnails/'

Exclude by file extension

--exclude='*.mp4'

Comments are disabled for this gist.