October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Copy Directories in Linux with cp, scp, and rsync

Use cp for local copies, scp for simple SSH transfers, and rsync for repeatable synchronization. These commands show the exact syntax, preservation options, and trailing-slash behavior that controls destination layout.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use cp for a one-time copy on the same machine, scp for a straightforward directory transfer over SSH, and rsync when you will repeat the transfer, synchronize a tree, exclude files, or avoid resending unchanged data. The commands differ most in where they work, what metadata they preserve, and how they place the source directory at the destination.

Choose the command that matches the job

Command Where it copies Best fit Recursive directory syntax Preservation and repeat transfers
cp Local filesystem only One-time local copy cp -R, cp -r, or cp -a -a is the archive form when preservation is wanted; it has no network or delta-transfer feature
scp Between hosts over SSH Simple remote upload or download scp -r -p preserves modification times, access times, and mode bits; repeated runs transfer through the SSH copy operation rather than a documented delta algorithm
rsync Local or remote Synchronization, backups, mirroring, exclusions, and repeated transfers rsync -r (or the commonly used archive form, -a) Its delta-transfer algorithm sends only differences; it can use a remote shell or an rsync daemon

GNU Coreutils documents that cp does not copy directories by default. OpenSSH’s scp recursively copies a directory with -r, while rsync uses recursive mode for directory trees.

Copy a directory on the same Linux machine with cp

Use the archive form when the copy should retain filesystem metadata:

cp -a source_dir destination_dir/

This places source_dir inside destination_dir. If destination layout matters, ensure the destination path exists or choose the intended new pathname explicitly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use recursive copy without archive preservation

cp -r source_dir destination_dir/

-R is another recursive spelling. Choose -r or -R when copying the directory tree is sufficient and archive-style preservation is not required.

Common cp mistake

Running cp source_dir destination_dir/ without a recursive option fails because directories are not copied by default. Add -a, -r, or -R rather than treating the directory like a single regular file.

Copy a directory to another host with scp

Push a local directory to a remote host

scp -r source_dir user@host:/remote/path/

This opens an SSH transfer and recursively sends the directory tree. Replace user, host, and /remote/path/ with the account, system name or address, and destination path you can access.

Preserve times and mode bits

scp -r -p source_dir user@host:/remote/path/

The -p option preserves modification times, access times, and mode bits. Use it when those attributes are part of the copy requirement; it does not turn scp into a synchronization tool.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pull a directory from a remote host

scp -r user@host:/remote/path/source_dir ./destination/

The remote path appears before the local destination. The current OpenSSH implementation uses SFTP for the transfer while retaining the familiar scp command interface.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Synchronize directories with rsync

rsync works both between local paths and across hosts. Its delta-transfer algorithm compares the source and destination and sends only differences, which is useful after the first copy. It can operate through a remote shell or an rsync daemon.

Push directory contents to a remote host

rsync -a source_dir/ user@host:/remote/path/

Here, the trailing slash on source_dir/ means “copy the contents of this directory.” Files and subdirectories from inside source_dir are placed directly under /remote/path/.

Pull directory contents from a remote host

rsync -a user@host:/remote/path/source_dir/ ./destination/

The same trailing-slash rule applies to a remote source: the contents of source_dir go into ./destination/.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Put the source directory itself below the destination

rsync -a source_dir user@host:/remote/path/

Without the slash, rsync copies the directory named source_dir as an entry below /remote/path/, producing /remote/path/source_dir (with its contents). This single character is the most important rsync destination-layout distinction.

Use recursive mode explicitly

rsync -r source_dir/ user@host:/remote/path/

The -r option tells rsync to copy directories recursively. The -a form used in the examples is the usual choice when an archive-style directory transfer is wanted.

How destination layout differs

Command Source written as Result under destination
cp -a source_dir destination_dir/ Directory name destination_dir/source_dir
scp -r source_dir user@host:/remote/path/ Directory name The remote destination contains source_dir
rsync -a source_dir/ user@host:/remote/path/ Directory contents (trailing slash) Contents go directly into /remote/path/
rsync -a source_dir user@host:/remote/path/ Directory itself (no trailing slash) /remote/path/source_dir is created or updated

Practical decision guide

  • Choose cp when both paths are on one machine and this is a local, one-time copy. Use -a if preservation matters.
  • Choose scp when the source and destination are different hosts, SSH is available, and straightforward recursive copying is all you need. Add -p for times and mode bits.
  • Choose rsync for repeated synchronization, backups, mirrors, exclusions, or large trees where avoiding retransmission of unchanged data matters. Decide deliberately whether the source path ends in /.

Checks before running a directory copy

  • Confirm the source path and whether it names a directory or its contents.
  • Confirm that the destination account can write to the target path.
  • For remote commands, verify the SSH host, username, and remote path.
  • Decide whether metadata preservation is required before choosing cp -a, scp -p, or an archive-style rsync command.
  • For rsync, inspect every source path for the trailing slash so the resulting directory layout is intentional.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.