📜  scp bash 命令 - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:05:05.782000             🧑  作者: Mango

SCP Bash Command

SCP (Secure Copy) is a command-line tool used in Linux/Unix-based systems to securely and efficiently transfer files between two remote hosts. The SCP command uses the Secure Shell (SSH) protocol for secure data transfer.

Syntax

The syntax for the SCP command is as follows:

scp [options] source_file target_file
Options

The following are the most commonly used options in the SCP command:

  • -P: Specifies the port number to connect to the remote host.
  • -r: Recursively copies the entire directory from the source host to the target host.
  • -v: Verbose mode. Displays the detailed information about the transferred files.
  • -p: Preserves the timestamp, permission, and ownership of the copied files and directories.
Examples

To copy a file from the local host to a remote host, use the following command:

scp localfile.txt username@remotehost:/path/to/destination

To copy a file from a remote host to the local host, use the following command:

scp username@remotehost:/path/to/source-file local-destination

To copy an entire directory from the local host to a remote host, use the following command:

scp -r local-directory username@remotehost:/path/to/remote-destination

To copy an entire directory from a remote host to the local host, use the following command:

scp -r username@remotehost:/path/to/remote-directory local-destination
Conclusion

The SCP command is a powerful tool for transferring files between two remote hosts securely and efficiently. With its simple syntax and various options, it can make file transfer tasks easy for programmers.