Linux provides two commands for file copy, CP and SCP, but they are slightly different.
- CP --- mainly used to copy files back and forth between different directories on the same computer
- SCP --- copy files back and forth between different Linux systems
Usage of CP:
Basic command format:
CP [Options] source DEST --- copy the file from the Source Path to the target path
CP [Options] source... directory --- copy multiple source files to the specified directory (multiple source files are separated by spaces)
Options:
-A same as-DPR copies the source file status, permissions, and other materials as far as possible, and uses recursive copy;
-R indicates recursive copy. If the source contains the directory name, all files in the directory are copied to the destination in sequence;
-F indicates force. If an object with the same file name already exists in the destination, delete the object before copying;
Example:
1. copy the file AAA (already exists) and name it BBB:
CP aaa bbb
2. Copy all C language programs to the finished subdirectory:
Cp *. c finished/
Usage of SCP:
There are three common methods to copy files between Linux:
The first is FTP, that is, installing FTP server in one of Linux, so that you can use the FTP client program on another machine to copy files.
The second method is to use the samba service, similar to the Windows file copy method, which is simple and convenient.
The third is to use the SCP command to copy files.
SCP is a file copy with security and is used for SSH logon.
Basic command format:
SCP [Options] file_source file_target
Options:
-V is the same as-V in most Linux commands. It is used to display the progress. It can be used to view the connection, authentication, or configuration error.
-C enable compression options
-P: select the port. Note that-P has been used by RCP.
Copy from local to remote
SCP/home/daisy/full.tar.gz root@172.19.2.75:/home/root ), copy the Directory and add the parameter-R.
Copy from remote to localSCP root @/172.19.2.75:/home/root/full.tar.gz/home/daisy/full.tar.gz