📦 Command: scp (Secure Copy)
The scp command is a network utility used to copy files and directories between two locations securely. It uses the SSH (Secure Shell) protocol for data transfer, ensuring that your files are encrypted while they travel over the network.
1. The "Why"
As a developer and researcher, you constantly need to move data across devices.
- Backup Your Work: Move your source code from your Linux PC to a remote backup server.
- Deploy Web Projects: Upload your Markdown documentation files to your web server's
/var/www/directory. - Mobile Development: Move compiled
.apkfiles or assets from your PC to your phone (if running an SSH server like Termux).
2. Basic Syntax
The logic follows the standard cp command: scp [source] [destination].
3. Practical Examples
A. Upload a Local File to a Remote Server
To move a file from your current folder to a remote user's home directory:
scp main.java user@192.168.1.50:/home/user/
B. Download a Remote File to Your PC
To pull a file from a server down to your current local directory (the . represents "here"):
scp user@192.168.1.50:/home/user/notes.txt .
C. Copying an Entire Directory
To copy a whole folder (like your e-book project), you must use the -r (recursive) flag:
scp -r ./ecommerce-blueprint user@myserver.com:/var/www/html/
D. Specifying a Different Port
If your server uses a non-standard port (not 22), use the capital -P:
scp -P 2222 data.zip user@myserver.com:/tmp/
4. Comparison: scp vs. rsync
While scp is great for quick transfers, many Arch users prefer rsync for larger projects.
| Feature | scp |
rsync |
|---|---|---|
| Speed | Fast for single files. | Faster for updates (only sends changes). |
| Interruption | Starts over if it fails. | Can resume where it left off. |
| Encryption | Always uses SSH. | Can use SSH or its own daemon. |
5. Pro-Tips
- Wildcards: You can use
*to move multiple files:scp *.pdf user@host:~/documents/. - SSH Config: If you have set up a
~/.ssh/configfile (as mentioned in thesshguide),scpwill recognize your aliases. You can just typescp file myserver:/path. - Security First: Because
scpis based on SSH, if you’ve already added your SSH Key to the remote server, you won’t have to type a password to move files. - Arch Linux Context: You might use
scpto move custom Hyprland config files or.dotfilesbetween multiple machines to keep your environment consistent.
6. Summary Reference
| Goal | Command |
|---|---|
| Upload File | scp [file] [user]@[host]:[path] |
| Download File | scp [user]@[host]:[path] [local_path] |
| Copy Directory | scp -r [folder] [user]@[host]:[path] |
| Custom Port | scp -P [port] [file] [user]@[host]:[path] |