scp command (Linux / bash / sh / zsh)
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 / option | Meaning |
|---|---|
| -r | Copy directories recursively. |
| -P PORT | Use a specific SSH port. |
| -i FILE | Use a selected identity key. |
| -p | Preserve 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.
Related commands
- sshOpen a secure remote shell or run a command over SSH.
- cpCopy files or directory trees to another location.
- curlTransfer data to or from URLs using many network protocols.
- ipconfigDisplay and manage Windows IP configuration and DNS client state.
- pingTest reachability and measure response time with ICMP echo requests.
- pingTest IP reachability and measure round-trip response time.
- Invoke-WebRequestSend HTTP and HTTPS requests and return response metadata and content.
- netstatDisplay active connections, listening ports, routing data, and protocol statistics.
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.