How to transfer files with scp and rsync in Linux
· Category: Linux
Short answer
scp copies files over SSH; rsync synchronizes directories with delta transfer for efficiency.
Steps
- Copy a file with scp:
scp file.txt user@remote:/path/
- Copy recursively:
scp -r localdir/ user@remote:/path/
- Sync with rsync:
rsync -avz localdir/ user@remote:/path/
- Sync with delete:
rsync -avz --delete localdir/ user@remote:/path/
Tips
rsync -Pshows progress and resumes partial transfers.- Use
--excludeto skip files during sync. rsyncover SSH is the standard for backups and deployments.
Common issues
- Trailing slashes in
rsyncpaths matter:dir/copies contents;dircopies the folder. - Permission denied: ensure the remote user has write access.