2.0 KiB
2.0 KiB
🔄 Rsync
rsync is a powerful command-line tool for syncing files and directories between systems over SSH.
Here are some useful commands 👇
📌 Basic Syntax
rsync [options] <file_or_dir> <user>@<host>:<target-dir>
or
rsync [options] <user>@<host>:<source-dir_or_file> <target-dir>
📥 Copy from Local ➝ Remote
rsync file1.txt radin@192.168.1.10:/home/radin
Verbose mode (shows details):
rsync -v file1.txt radin@192.168.1.10:/home/radin
📤 Copy from Remote ➝ Local
rsync -v radin@192.168.1.10:/home/radin/file1.txt /opt
📦 Archiving
Archive mode (preserves permissions, symlinks, etc.):
rsync -va file1.txt radin@192.168.1.10:/home/radin
Archive + compress (gzip):
rsync -vaz file1.txt radin@192.168.1.10:/home/radin
With progress bar:
rsync -vaz --progress file1.txt radin@192.168.1.10:/home/radin
🔐 Custom SSH Port
rsync -e 'ssh -p 8090' -vaz file1.txt radin@192.168.1.10:/home/radin
🗑️ Sync with Delete (mirror directories)
Deletes files on destination that don’t exist on source:
rsync -vaz --delete dir_test/ radin@192.168.1.10:/home/radin
🚫 Excluding Files
Exclude .img files:
rsync -va dir_test/ --exclude '*.img' radin@192.168.1.10:/home/radin
⚡ Bandwidth Control
Limit transfer speed (in KB/s):
rsync -v --bwlimit=2048 file1.txt radin@192.168.1.10:/home/radin
🧹 Move Instead of Copy
Remove source file after transfer:
rsync -v --remove-source-file file1.txt radin@192.168.1.10:/home/radin
⛔ Ignore Existing Files
Skip already existing files:
rsync -v --ignore-existing file1.txt radin@192.168.1.10:/home/radin
🧹⛔ Combine Options
Remove source + ignore existing:
rsync -v --remove-source-file --ignore-existing file1.txt radin@192.168.1.10:/home/radin