buymeasoda RefDocs
  • Overview
  • General
    • Android
    • Apache
    • Fish
    • Git
    • Github
    • Gmail
    • Homebrew
    • iOS
    • iTerm
    • MacOS
    • MacPorts
    • Mamp
    • Media
    • Mercurial
    • MySQL
    • Node
    • npm
    • nvm
    • Obsidian
    • PHP
    • React Native
    • Rust
    • Server
    • Slack
    • Sourcegraph
    • Tools
    • Vim
    • VS Code
    • Yarn
  • Unix
    • Checksum and hash utilities
    • Command line history
    • Command line keyboard shortcuts
    • Compress files and folders
    • Crontab
    • Diff files and folders
    • Disk usage and file sizes
    • Find and search files
    • Firewall configuration
    • Help and manual pages
    • HostName and Local HostName for Mac OSX
    • Navigating the file system
    • Network, domains and routing
    • Run and manage background tasks
    • Secure FTP SFTP and Secure Copy SCP
    • Secure Shell SSH
    • Sync files and folders
    • System and process management
    • System and user information
    • Useful characters
    • Useful commands
    • User, file and group permissions
    • Working with cURL
    • Working with files and directories
    • Working with text
Powered by GitBook
On this page
  • Usage
  • Backup Mode
  • Archive Mode
  • Common Flags
  • Dry Run
  • Display Flags
  • Transfer Flags
  1. Unix

Sync files and folders

Usage

rsync <options> <source> <destination>

Backup Mode

Perform a mirrored one way sync of source files to destination, removing deleted files from destination (Archive mode flag -a is the same as -rlptgoD)

rsync -avhP --stats --delete <source> <destination>

Archive Mode

Perform a mirrored one way sync, deleting destination files but retain a destination backup of deleted files in a date stamped folder

rsync -avhP --stats --delete --backup --backup-dir="backup_$(date +\%Y-\%m-\%d)" <source> <destination>

Common Flags

Flags encompassed by archive mode

  • -r recurse into subdirectories

  • -l copy symlinks as symlinks

  • -p preserve permissions

  • -t preserve timestamp

  • -g preserve group

  • -o preserve owner

  • -D preserve device and special files

To opt out of an archive mode default flag

  • --no-<option> (eg. --no-D to disable -D)

Dry Run

  • -n dry run what will be transferred

Display Flags

  • -v verbose output

  • -h human readable output

  • -P show progress and keep partial files

Transfer Flags

  • -u skip files that are newer on the receiver

  • -z compress data during transfer

  • --delete delete extraneous files from destination dirs

  • --exclude=<pattern> exclude files matching <pattern>

PreviousSecure Shell SSHNextSystem and process management

Last updated 3 years ago