Skip to main content TerryFunggg Blog

Rsync Command

scp is transfer the files/folder to other location/PC eg send file to some server:

sh code snippet start

scp somefile user@ip:location

sh code snippet end

or get the file to local:

sh code snippet start

scp user@ip:location/file .

sh code snippet end

But it always single transfer.

For better synchronize files. We can use rsync

To sync local books folder to dist(maybr server) books folder:

sh code snippet start

rsync -auvc user@some_ip_addr:~/books/ books/

sh code snippet end

  • a: for archive
  • u: update, skip files that are newer
  • v: for verbosity
  • c: checksum, update base on file checksum, not mod-time and size change

More example from tldr:

sh code snippet start

 - Transfer a file:
   rsync path/to/source path/to/destination

 - Use archive mode (recursively copy directories, copy symlinks without resolving, and preserve permissions, ownership and modification times):
   rsync [-a|--archive] path/to/source path/to/destination

 - Compress the data as it is sent to the destination, display verbose and human-readable progress, and keep partially transferred files if interrupted:
   rsync [-zvhP|--compress --verbose --human-readable --partial --progress] path/to/source path/to/destination

 - Recursively copy directories:
   rsync [-r|--recursive] path/to/source path/to/destination

 - Transfer directory contents, but not the directory itself:
   rsync [-r|--recursive] path/to/source/ path/to/destination

 - Use archive mode, resolve symlinks, and skip files that are newer on the destination:
   rsync [-auL|--archive --update --copy-links] path/to/source path/to/destination

 - Transfer a directory from a remote host running rsyncd and delete files on the destination that do not exist on the source:
   rsync [-r|--recursive] --delete rsync://host:path/to/source path/to/destination

 - Transfer a file over SSH using a different port than the default (22) and show global progress:
   rsync [-e|--rsh] 'ssh -p port' --info=progress2 host:path/to/source path/to/destination

sh code snippet end