Skip to main content

Command referencescp

scp command (Linux / bash / sh / zsh)

Linuxbashshzshnetworkbeginner

What it does

Copy files securely between local and SSH-accessible hosts. When people search for the scp command linux file transfer, they usually want scp's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.

Copy files securely between local and SSH-accessible hosts.

Syntax

scp [OPTION]... SOURCE... TARGET

Common options

Flag / optionMeaning
-rCopy directories recursively.
-P PORTUse a specific SSH port.
-i FILEUse a selected identity key.
-pPreserve modification times and modes.

Practical examples

Upload file

scp build.zip admin@server:/srv/releases/

Copies a local build to the server.

Download file

scp admin@server:/var/log/app.log .

Copies a remote log locally.

Copy directory

scp -r assets/ admin@server:/srv/app/

Uploads the complete assets tree.

Common mistakes

  • Using lowercase `-p` for port; scp uses uppercase `-P`.
  • Forgetting that a missing colon can turn a remote-looking target into a local filename.

FAQ

What does scp do in Linux?

Copy files securely between local and SSH-accessible hosts.

How do I use scp from the terminal?

Start with `scp [OPTION]... SOURCE... TARGET`, then choose only the options needed for the task.

What is a practical scp example?

Try `scp build.zip admin@server:/srv/releases/` — Copies a local build to the server.

Can I use scp in a shell script?

Yes. scp works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.