CloudsArk
Commands Linux

scp Command Examples in Linux

Practice useful scp command examples for everyday Linux administration and troubleshooting.

scp Command Examples in Linux

Introduction

These examples show practical ways to use scp on a Linux terminal. Each example is written so you can adapt it for administration or troubleshooting.

Example 1: Basic Usage

scp file.txt admin@server:/tmp/

This is the simplest form of the command and is a good starting point before adding options.

Example 2: Common Admin Task

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

This example reflects a common task on RHEL, Rocky Linux, AlmaLinux, or similar systems.

Example 3: Useful Option

scp -r project admin@server:/srv/

This option helps narrow the result, change behavior, or handle a more realistic target.

Example 4: Real-World Scenario

scp -P 2222 -i ~/.ssh/id_rsa file.txt admin@server:/tmp/

Use this pattern when the task moves beyond a single basic command.

Example 5: Verification

ssh admin@server ls -l /tmp/file.txt

Example output:

-rw-r--r-- 1 admin admin 1200 May 30 10:00 /tmp/file.txt

Common Mistakes

  • Using lowercase -p when you meant uppercase -P for port.
  • Forgetting -r when copying a directory.
  • Putting the colon in the wrong place in a remote path.

Quick Reference

scp file.txt admin@server:/tmp/
scp admin@server:/var/log/app.log .
scp -r project admin@server:/srv/
scp -P 2222 -i ~/.ssh/id_rsa file.txt admin@server:/tmp/
ssh admin@server ls -l /tmp/file.txt

Summary

Good scp usage means choosing the right option, keeping the target clear, and verifying the result with output you can explain.