Linux · Systems fluency
How do scp and rsync differ, and when do you use each?
Short answer
scp copies files over SSH with simple semantics, while rsync synchronizes trees and transfers only differences. Use rsync for repeatable deployments and large transfers, and scp for a quick one-off copy.
rsync compares file metadata and content using a rolling checksum algorithm, so it can skip unchanged files and transfer only changed blocks. scp has no such optimization and is effectively a remote copy command.
scp -r ./build deploy@example.com:/srv/app/
rsync -av --progress ./build/ deploy@example.com:/srv/app/
rsync -av --dry-run --delete ./build/ deploy@example.com:/srv/app/Semantics that bite
- A trailing slash on the rsync source copies its contents, not the directory itself
- --delete removes destination files missing from the source, so always dry-run first
- -a preserves permissions, times, symlinks, and ownership where allowed
- -z compresses in transit, which may cost CPU on fast links
- --partial and --append-verify help with interrupted large transfers
Verify what actually arrived. Compare checksums or count files when correctness matters. A successful exit code means the transfer completed, not that the destination is logically correct.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What does a trailing slash mean in an rsync source path?
- 2Why is --delete dangerous without --dry-run?
- 3When would you avoid rsync compression?
- 4How do you verify a large file transfer?
Say it in the interview
scp is a straightforward copy over SSH, while rsync synchronizes trees and transfers only differences. I use rsync for deployments and large repeatable transfers, and I dry-run before using --delete. The trailing slash on the source is a common source of mistakes. I verify the result rather than trusting only the exit code.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Linux mock interview and get scored feedback on depth, clarity and confidence.