File Copying in Linux: cp vs rsync (with Examples)
1. What Is the cp Command?
cp is a standard Unix/Linux command for copying files and directories locally .
It is simple and fast for everyday file management.
Quick local copy —on the same machine or mounted filesystem.
Simple syntax —easy for basic file/directory tasks.
Not for remote copying —does not support copying to/from other computers directly.
3. Key Differences: cp vs rsync vs scp
Command
Local Copy
Remote Copy
Resume/Partial
Sparse
Incremental/Sync
cp
✅
❌
❌
✅
❌
rsync
✅
✅
✅
✅
✅
scp
❌
✅
❌
❌
❌
b. Copy a file to a directory
cp file1.txt /home/drew/Backup/
cp file1.txt file2.txt /home/drew/Backup/
d. Copy a directory recursively
cp -r myfolder /home/drew/Backup/
e. Preserve file attributes (timestamp, permissions)
cp -p file1.txt /home/drew/Backup/
f. Copy sparse files efficiently (e.g., VM images)
cp --sparse=always Trisquel.qcow2 /home/drew/Backup/
No resume: Interrupted copies must restart.
No remote copy: Can’t copy across network directly.
No incremental sync: Always copies whole file, even if unchanged.
6. Using rsync for Advanced Copying
rsync --progress file1.txt /home/drew/Backup/
rsync --progress file1.txt drew@morgan.local:/home/drew/Backup/
c. Resume partial transfer (if interrupted)
rsync --progress --partial --append-verify file1.txt drew@morgan.local:/home/drew/Backup/
--partial: Keep partially transferred files.
--append-verify: Resume and verify integrity.
rsync --sparse --progress Trisquel.qcow2 drew@morgan.local:/home/drew/Backup/
e. Copy entire directories
rsync -a --progress myfolder/ drew@morgan.local:/home/drew/Backup/myfolder/
-a (archive): Preserve permissions, timestamps, symlinks, etc.
Resume interrupted transfers .
Remote copying via SSH .
Efficient for large files and backups .
Supports sparse files, incremental updates, and verification .
8. Copying Remotely: Why Not cp?
cp cannot copy files directly to remote systems.
Use rsync (recommended) or scp for remote file transfer.
Task
Use cp
Use rsync
Simple local copy
✅
✅
Copy directory recursively
✅ (-r)
✅ (-a)
Preserve attributes
✅ (-p, -a)
✅ (-a)
Copy sparse files
✅ (--sparse)
✅ (--sparse)
Resume after interruption
❌
✅ (--partial --append-verify)
Copy to/from remote
❌
✅ (user@host:path)
Incremental backup/sync
❌
✅
10. Quick Reference: Commands
cp file.txt /path/to/destination/
Local directory copy (recursive)
cp -r mydir/ /path/to/destination/
cp --sparse=always myimage.qcow2 /path/to/destination/
Remote copy (with resume)
rsync --partial --append-verify --progress file.img user@host:/path/to/destination/
Remote directory copy (with archive)
rsync -a --progress mydir/ user@host:/path/to/destination/
For quick, small local copies , use cp.
For large files, remote transfers, or interrupted jobs , use rsync.
If you only need a one-way remote copy (no resume), scp is an option, but rsync is safer and more flexible.
Feel free to copy, edit, or share this guide in your Gist or documentation!