Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Copy Large Files Faster Linux: 8 Proven Ways

· 5 min read · Home Tech

In this article
  1. Why Standard cp Is Slow for Big Files
  2. Understanding the Bottlenecks
  3. Tool Comparison: cp vs rsync vs dd vs tar
  4. Step-by-Step: Optimizing rsync for Large Files
  5. Using dd for Raw Speed
  6. Network Transfers: SSH vs Netcat
  7. Parallel Copying with GNU Parallel
  8. Filesystem and Mount Options
  9. Frequently Asked Questions

To copy large files faster on Linux, use rsync with the -W (whole-file) flag over a local network, or use dd with a large block size for raw device-to-device copies. For everyday large file transfers, rsync with compression and checksum options often beats the default cp command by a significant margin.

Why Standard cp Is Slow for Big Files

The default cp command reads and writes data in small chunks (often 4–64 KB), which causes excessive system calls and context switches. For a 10 GB file, that means millions of tiny read/write operations. The filesystem cache also gets thrashed, and the disk may not reach its full sequential throughput. Additionally, cp does not verify the copy, so a silent corruption can go unnoticed.

Understanding the Bottlenecks

Before choosing a tool, identify where the slowdown occurs:

  • Disk speed – HDDs top out around 150–200 MB/s; SSDs can do 500 MB/s to several GB/s.
  • Network speed – Gigabit Ethernet caps at ~112 MB/s, 10GbE at ~1.1 GB/s.
  • Filesystem overhead – Metadata updates, journaling, and fragmentation affect performance.
  • CPU and RAM – Compression and checksumming consume CPU; insufficient RAM reduces caching.

Use iotop or nload to see where the bottleneck is. If the disk is at 100% while the network is idle, focus on disk optimizations.

Tool Comparison: cp vs rsync vs dd vs tar

  • cp – Best for small numbers of files; no checksum, no resume, no compression.
  • rsync – Best for large files and directories; supports resume, compression, checksums, and delta transfer.
  • dd – Best for raw block copies (e.g., cloning a disk); can bypass filesystem overhead.
  • tar – Best for bundling many small files into one stream, which reduces overhead.

For a single 20 GB ISO file, rsync -W is often the fastest because it disables delta transfer and uses a large block size. For a directory with thousands of small files, tar piped over SSH can be faster than rsync because it creates a single stream.

Step-by-Step: Optimizing rsync for Large Files

  1. Use -W (whole-file) to skip delta transfer for local copies: rsync -W source dest.
  2. Add --progress to see transfer speed and ETA.
  3. Increase the I/O buffer with --io-buffer-size=1M (or higher, e.g., 8M).
  4. If copying over a network, add -z for compression only if the file is compressible (e.g., text, logs). For already-compressed files (ISO, JPEG, MP4), compression wastes CPU.
  5. Use --partial to keep partially transferred files if the connection drops.
  6. For local copies, consider --inplace to avoid creating a temporary file.

Example: rsync -W --progress --io-buffer-size=8M /data/bigfile.iso /backup/

Using dd for Raw Speed

dd copies data in blocks directly from source to destination, bypassing the filesystem cache. The key parameter is bs (block size). A block size too small causes overhead; too large wastes memory. For modern disks, 1M to 64M is typical.

Example: dd if=/dev/sda of=/dev/sdb bs=64M status=progress

This copies the entire disk, including partition table and unused space. For a single file, dd if=file of=file2 bs=1M works but offers no checksum or resume. dd is best for cloning drives or creating exact images, not for everyday file copies.

Network Transfers: SSH vs Netcat

When copying over a network, SSH adds encryption overhead. For trusted local networks, netcat (nc) can be faster because it skips encryption. Example:

On the receiver: nc -l -p 9000 | tar xv
On the sender: tar cv . | nc receiver_ip 9000

This streams the directory without encryption. However, there is no integrity check. For secure transfers, use rsync over SSH with compression disabled (-z off) and a larger buffer.

Parallel Copying with GNU Parallel

For many large files, copying them sequentially underutilizes the disk. Use parallel to copy multiple files at once, but be careful: too many parallel copies can thrash the disk. A good starting point is parallel -j 4 for HDDs and -j 8 for SSDs.

Example: ls *.iso | parallel -j 4 rsync -W {} /dest/

This launches four rsync processes simultaneously. Monitor with iostat to see if the disk is saturated.

Filesystem and Mount Options

Mount options can affect copy speed. For ext4, consider noatime to avoid updating access times. For network filesystems like NFS, adjust the rsize and wsize to 1M or larger. For USB drives, ensure they are mounted with sync off (the default) to allow write caching.

Also, check if the destination filesystem is full or fragmented. Use df -h and fsck if needed.

Frequently Asked Questions

Why is rsync slower than cp for a single large file?

By default, rsync computes checksums and may use delta transfer, which adds overhead. Using -W disables delta transfer and makes it comparable to cp, but rsync still has more overhead. For a single file, cp can be faster if the filesystem is fast. However, rsync offers resumability and verification, which are worth the slight speed loss.

Does compression help when copying over a network?

Only if the file is compressible. Text files, logs, and source code compress well. Already compressed files (ISO, ZIP, JPEG, MP4) will not shrink and will waste CPU. Use rsync -z only when you know the data is compressible.

How do I resume an interrupted copy?

Use rsync --partial --append-verify. This keeps the partially copied file and appends the missing data. The --append-verify flag checks the existing part before appending. For cp, there is no built-in resume; you would need to restart the copy.

Is it safe to use dd on a mounted filesystem?

No, dd on a mounted filesystem can lead to corruption because the kernel may have cached data that hasn't been written. Always unmount the filesystem before using dd for a raw device copy. For file-level copies, use rsync or cp instead.

What is the fastest way to copy a directory with 100,000 small files?

Tar piping is often fastest because it creates a single stream, reducing metadata overhead. Example: tar cf - . | (cd /dest && tar xf -). Alternatively, use rsync -W with a large buffer. Parallel copies can also help, but be careful with disk I/O.

Does using a larger block size always make dd faster?

Up to a point. Block sizes beyond 64M rarely help and can waste memory. The optimal size depends on the disk's cache and the filesystem. Test with bs=1M, 4M, 16M, and 64M to see which gives the best throughput.