Skip to main content

Wildcard and Multiple Files

SCP supports shell glob patterns and multiple file arguments, making it easy to transfer groups of files in a single command.

Glob Patterns (Local Source)

When copying from local, your shell expands the glob before SCP runs.

1. Copy All Files of a Type

Command:

scp ./*.sql admin@db-server:/backups/

Output:

users.sql                              100%   12MB  35.0MB/s   00:00
orders.sql 100% 45MB 40.1MB/s 00:01
products.sql 100% 8MB 32.0MB/s 00:00

2. Copy All Files Matching a Pattern

Command:

scp ./report-2026-*.pdf admin@server:/reports/

Output:

report-2026-01.pdf                     100%    2MB  18.5MB/s   00:00
report-2026-02.pdf 100% 3MB 20.1MB/s 00:00

Glob Patterns (Remote Source)

When copying from remote, you must quote the glob so your local shell does not expand it prematurely.

3. Download Remote Files with a Glob

Command:

scp 'admin@server:/var/log/nginx/*.log' ./logs/

Output:

access.log                             100%   50MB  38.0MB/s   00:01
error.log 100% 5MB 25.0MB/s 00:00
Quote Remote Globs

Without quotes, your local shell tries to expand the *, which will fail or match local files. Always wrap remote paths containing wildcards in single quotes.

4. Download Remote Files with Braces

Command:

scp 'admin@server:/etc/nginx/{nginx.conf,mime.types}' ./

Output:

nginx.conf                             100% 4096     2.5MB/s   00:00
mime.types 100% 5120 3.0MB/s 00:00

Multiple File Arguments

You can list multiple source files explicitly.

5. Copy Several Named Files

Command:

scp ./file1.txt ./file2.txt ./file3.txt admin@server:/data/

Output:

file1.txt                              100% 1024     1.0MB/s   00:00
file2.txt 100% 2048 1.5MB/s 00:00
file3.txt 100% 4096 2.0MB/s 00:00

6. Mix Local and Different Paths

Command:

scp /etc/hosts /home/user/.bashrc admin@server:/tmp/configs/

Output:

hosts                                  100%  221     0.5MB/s   00:00
.bashrc 100% 3526 2.1MB/s 00:00

Using tar + SCP for Large File Sets

For many small files, tar + SCP is significantly faster than scp -r because it avoids per-file SSH overhead.

7. Tar and Stream in One Command

Command:

tar czf - ./project/ | ssh admin@server "tar xzf - -C /opt/apps/"

Output:

(no output on success — data streams directly)

This is faster than scp -r for directories with thousands of small files.

Pattern Reference

PatternMatchesExample
*.txtAll .txt filesscp ./*.txt host:/path/
file?.logfile1.log, fileA.log, etc.scp ./file?.log host:/path/
{a,b,c}.confExactly a.conf, b.conf, c.confscp './{a,b,c}.conf' host:/path/
backup-202[56]*Files starting with backup-2025 or backup-2026scp ./backup-202[56]* host:/path/

What's Next?

Explore advanced features like custom ports and jump hosts in Port and Identity.