📜  rsync - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:47:08.030000             🧑  作者: Mango

rsync - Shell-Bash

rsync is a command-line utility that is used to synchronize files and directories between two different systems. It is used to copy files from one location to another, potentially across a network connection, while optimizing for speed and minimizing data transfer.

Features

Some of the key features of rsync include:

  • Ability to transfer files locally or remotely, with or without compression
  • Ability to transfer only the changed parts of a file rather than the whole file
  • Ability to resume interrupted file transfers
  • Ability to exclude and include specific files or directories during transfers
  • Supports bandwidth throttling for better network utilization
  • Supports checksumming to ensure data integrity during transfers
  • Supports mirroring options for replicating entire directory structures
Usage

The basic syntax for rsync is as follows:

rsync [OPTION]... SRC [SRC]... [DEST]

Here, SRC refers to the source file or directory that needs to be copied, and DEST refers to the destination location where the files need to be copied.

Some common options that are used with rsync include:

  • -a, --archive: Archive mode, which preserves permissions, timestamps, etc. during transfers
  • -v, --verbose: Verbose mode, which displays more information during transfers
  • -z, --compress: Compresses files during transfers to reduce network usage
  • -r, --recursive: Recursive mode, which transfers directories and their contents
  • -n, --dry-run: Dry run mode, which simulates transfers without actually copying anything
Examples

Here are some examples of how rsync can be used:

  1. Copy files from local directory to remote server:
rsync -avz /local/directory user@remote:/remote/directory
  1. Copy files from remote server to local directory:
rsync -avz user@remote:/remote/directory /local/directory
  1. Sync two directories (local or remote):
rsync -avz /dir1/ /dir2/
  1. Excluding specific files or directories during transfers:
rsync -avz --exclude 'dir1/file1.txt' /dir1/ /dir2/
  1. Throttle bandwidth usage during transfers:
rsync -avz --bwlimit=1000 /dir1/ user@remote:/dir2/
Conclusion

rsync is a powerful tool that can simplify file transfers between systems, particularly over a network. With its ability to optimize for data transfer speed and minimize network usage, rsync is a must-have utility for any developer or system administrator.