How to Use SCP in Linux: A Step-by-Step Guide with Practical Code Examples for Seamless File Transfer
scp
stands for secure copy, and it is a command-line tool for securely transferring files between local and remote hosts over a network. Here are some practical examples of scp
usage:
- Copy a file from the local host to a remote host:
scp /path/to/local/file username@remote_host:/path/to/remote/directory
- Copy a file from a remote host to the local host:
scp username@remote_host:/path/to/remote/file /path/to/local/directory
- Copy a directory recursively from the local host to a remote host:
scp -r /path/to/local/directory username@remote_host:/path/to/remote/directory
- Copy a directory recursively from a remote host to the local host:
scp -r username@remote_host:/path/to/remote/directory /path/to/local/directory
- Copy multiple files from the local host to a remote host:
scp /path/to/local/file1 /path/to/local/file2 username@remote_host:/path/to/remote/directory
- Copy multiple files from a remote host to the local host:
scp username@remote_host:/path/to/remote/file1 username@remote_host:/path/to/remote/file2 /path/to/local/directory
- Copy a file using a different port number:
scp -P port_number /path/to/local/file username@remote_host:/path/to/remote/directory
These are just some examples of scp
usage. The options and syntax may vary depending on the operating system and version of scp
. It’s important to note that scp
is a secure way of copying files between hosts, but it is not the most efficient method for transferring large amounts of data.