rcp - macOS


Overview

rcp (remote copy) is a command-line utility for copying files between local and remote hosts. It supports both file transfer and directory recursion, making it effective for synchronization and backup tasks.

Syntax

rcp [options] source-path destination-path

Options/Flags

-r

  • Recursively copy directories and their contents.

-p

  • Preserve file attributes (permission, ownership, modification time).

-v

  • Operate in verbose mode, displaying progress and detailed information.

-P

  • Do not follow symbolic links (default behavior).

-E

  • Preserve symbolic links, copying them as symbolic links.

-H

  • Preserve hard links (default behavior).

-L

  • Preserve soft links, copying them as soft links.

-n

  • Do not overwrite existing files.

-a

  • Implies -rlptvAH.

-t

  • Copy only modification times.

Examples

Basic file transfer:

rcp ~/Documents/file.txt user@remote-host:/tmp/

Recursively copy directory:

rcp -r ~/Projects/ my-project/ user@remote-host:~/

Preserve attributes and follow symbolic links:

rcp -pvH ~/Documents/file.txt user@remote-host:/tmp/

Copy only modification times:

rcp -t ~/Documents/file.txt user@remote-host:/tmp/

Common Issues

  • Permission errors: Ensure you have sufficient permissions to access both the source and destination files/directories.
  • Connection issues: Verify network connectivity and the remote host’s SSH/FTP settings.
  • Destination file already exists: Use the -n option to prevent overwriting existing files.

Integration

rcp can be used with the following commands for advanced tasks:

  • rsync: Use rcp as a remote shell command for rsync, enabling efficient and incremental file transfers.
  • ssh: Integrate with SSH for secure file transfer over encrypted connections.
  • ftp: Utilize FTP for transferring files to/from remote FTP servers.
  • rsync: Advanced file transfer tool with features like incremental updates and bandwidth control.
  • scp: Secure file transfer utility that operates over SSH connections.
  • ftp: Command-line tool for transferring files via the File Transfer Protocol (FTP).