Master Secure Copy and Rsync: Essential Tips, Parameters, and Best Practices
Learn how to efficiently transfer files between Linux servers using SCP and Rsync, compare their features, understand key command options, handle symlinks, progress display, bandwidth limits, filtering, and hidden files, and apply practical tips for reliable remote copying.
scp (secure copy) is a Linux command for remote file copying, similar to cp but works across servers and encrypts data.
When a server's filesystem becomes read‑only, scp can be used to retrieve files. It consumes minimal resources compared with rsync, which may cause higher I/O on many small files.
Generally rsync is preferred for synchronization because it transfers only differences, supports incremental backups, and can compare file modification time and size. Rsync transfers changed blocks, while scp transfers whole files. Rsync is not encrypted by default, whereas scp provides encrypted transfer.
SCP common options
-B Batch mode (no password prompts)</code>
<code>-C Enable compression (passes -C to ssh)</code>
<code>-p Preserve modification, access times and permissions</code>
<code>-q Suppress progress meter</code>
<code>-r Recursively copy directories</code>
<code>-v Verbose output (debug information)</code>
<code>-c cipher Specify encryption cipher (passed to ssh)</code>
<code>-F ssh_config Use alternative ssh configuration file</code>
<code>-i identity_file Use private key file for authentication</code>
<code>-l limit Limit bandwidth in Kbit/s</code>
<code>-o ssh_option Pass ssh options</code>
<code>-P port Specify remote port (uppercase P)</code>
<code>-S program Specify program for encrypted transportRsync common options
-a, --archive Archive mode; recursive, preserve attributes (equivalent to -rlptgoD)</code>
<code>-v, --verbose Verbose output</code>
<code>-p, --perms Preserve permissions</code>
<code>-g, --group Preserve group</code>
<code>-o, --owner Preserve owner</code>
<code>-r, --recursive Recurse into directories</code>
<code>-l, --links Preserve symbolic links</code>
<code>-H, --hard-links Preserve hard links</code>
<code>-e, --rsh=COMMAND Specify remote shell (ssh)</code>
<code>-z, --compress Compress file data during transfer</code>
<code>--stats Show transfer statistics</code>
<code>--progress Show progress during transfer</code>
<code>--timeout=TIME Set I/O timeout in seconds</code>
<code>--delete Delete files in destination that are absent in source</code>
<code>--delete-before Delete before receiving files</code>
<code>--delete-after Delete after transfer</code>
<code>--delete-excluded Delete excluded files from destination</code>
<code>--ignore-errors Continue despite I/O errors</code>
<code>--exclude PATTERN Exclude files matching pattern</code>
<code>--exclude-from FILE Read exclude patterns from FILE</code>
<code>--version Show version</code>
<code>--port=PORT Specify rsync daemon port</code>
<code>--log-format=FORMAT Define log format</code>
<code>--password-file=FILE Read password from FILE</code>
<code>--bwlimit=KBPS Limit I/O bandwidthPractical tips for remote copying
1. Handling symbolic links
Rsync copies symlinks when the -l option is used. SCP does not preserve symlinks; to copy them you can archive the source directory with tar -zcvf test.tar.gz test, transfer the archive, then extract it on the target.
2. Showing progress
Rsync displays a progress bar with --progress. SCP shows progress when the -v (verbose) flag is used, even across machines; without -v it shows no progress.
3. Bandwidth limiting
Rsync limits bandwidth with --bwlimit=KBPS (e.g., --bwlimit=1000 for 1 MB/s). SCP limits bandwidth with the -l option (e.g., -l 1024 for 1 MB/s).
4. Filtering files
Rsync can exclude files or directories using --exclude=PATTERN or --exclude-from=FILE. Patterns must be simple names, not full paths, and can include wildcards. Multiple --exclude options can be combined.
5. Copying hidden files
To copy hidden files with rsync, include a trailing slash on the source directory (e.g., rsync -av /path/to/source/ user@host:/path/to/dest/). With SCP, use scp -rp -P 22 /path/to/source/. user@host:/path/to/dest/ to include dotfiles.
For more details, see the original article: https://www.cnblogs.com/kevingrace/p/8529792.html
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
