Use cp to copy a directory on the same system, scp to transfer it simply over SSH, and rsync when you need repeat transfers, exclusions, or more efficient synchronization. The key detail with rsync is its source-path slash: source_dir/ copies the directory’s contents, while source_dir includes the directory itself beneath the destination.
Choose the right Linux directory-copy command
| Command | Best for | Recursive copying | Preservation and repeat transfers |
|---|---|---|---|
cp |
Local copies on the same system | Use -R, -r, or -a; directories are not copied by default, according to the GNU Coreutils manual. |
-a is the archive form when preservation is wanted. It is not intended to reduce data sent during a later remote transfer. |
scp |
Straightforward transfers between hosts over SSH | Use -r to copy an entire directory, as documented in the scp manual. |
-p preserves modification times, access times, and mode bits. Use it when those attributes matter. |
rsync |
Repeat transfers, backups, mirroring, and exclusions | Use -r for recursion; -a is commonly used when copying directory trees. |
Its delta-transfer algorithm sends differences rather than retransmitting unchanged data. It can operate locally or remotely through a remote shell or daemon, as described in the rsync manual. |
Copy a directory locally with cp
GNU Coreutils notes that cp does not copy directories by default. Use the archive option for a directory-tree copy when preservation is wanted:
cp -a source_dir destination_dir/
If archive preservation is not needed, use recursive copying instead:
cp -r source_dir destination_dir/
These are local-copy patterns. For a copy to or from another host, use scp or rsync.
#1 Best Overall
Transfer a directory over SSH with scp
scp copies files between hosts over an SSH connection. In current OpenSSH, it uses SFTP for the transfer. Add -r to copy a directory and its contents.
Push a local directory to a remote host
Run this on the system that has the source directory:
scp -r source_dir user@host:/remote/path/
To preserve modification times, access times, and mode bits as well, add -p:
scp -rp source_dir user@host:/remote/path/
Pull a remote directory to the local system
Run this on the system where you want the copy to be created:
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutescp -r user@host:/remote/path/source_dir ./destination/
Use -p in the same way if preserving times and mode bits is required.
Rank #4
Use rsync for repeat transfers and synchronization
rsync supports local copies and remote transfers, and its delta-transfer algorithm is designed to send only differences during transfers. That makes it useful for recurring copies, backups, and mirroring. Its manual describes -r as the option for recursively copying directories; the archive form -a is a common choice for directory trees.
Push directory contents to a remote destination
rsync -a source_dir/ user@host:/remote/path/
With the slash after source_dir, rsync copies the contents into /remote/path/. Without that slash, rsync includes the source directory itself below the destination:
Best Value
rsync -a source_dir user@host:/remote/path/
Pull remote directory contents locally
rsync -a user@host:/remote/path/source_dir/ ./destination/
The trailing slash on the remote source means the contents of source_dir go into ./destination/. Omit the slash when you want the source directory itself to appear below the destination.
Exclude files or directories
Rsync supports filtering and exclusions, which is useful when a backup or synchronization should leave out selected paths. For example, add an exclusion pattern with --exclude:
rsync -a --exclude='*.tmp' source_dir/ user@host:/remote/path/
Check the resulting source and destination layout before a large transfer, particularly when changing whether the source path ends in a slash.
Quick Recap
How to choose
- Choose
cp -afor a one-time local directory copy when archive preservation is wanted. - Choose
scp -rfor a simple directory transfer between hosts over SSH; add-pwhen times and mode bits should be preserved. - Choose
rsyncfor repeated synchronization, backups, mirroring, or exclusions, especially when reducing retransmission of unchanged data matters.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

