The files in Linux copy the cp command and scp command for details
- 2020-05-30 21:43:03
- OfStack
The files in Linux copy the cp command and the scp command
Two commands, cp and scp, are often used to copy files locally or transfer files to other computers when using an operating system.
The cp command is used to copy files or directories. scp is short for secure copy and is used for remote transmission of files or directories encrypted under Linux.
cp and scp are powerful and commonly used commands in Linux. Here's how to use cp and scp.
cp command
The cp command can copy a file, a single file or a whole directory.
cp [options] source dest
For example, cp test.txt test1.txt copies test.txt as a file test1.txt.
The common cp command options are:
`-r`: Copy the directory file and copy the files in the directory to the target directory in order
`-f`: If the same file name already exists in the target file, delete the file with the same name before copying
`-l`: Hard links to source files rather than copying files
`-u`: The source file Modification Time Copy is made only when the destination file is updated.
`-v`: Output details
Copy folder command:
cp -r test/ test1/
scp command
The scp command enables two-way transmission between local and remote servers, where local files can be transferred to remote services or files from remote servers can be transferred locally and encrypted.
The basic format of the scp command:
scp [options] source dest
scp common command options:
`-P`: The default port for data transfer, the default is 22
`-r`: Recursively copies the entire directory
`-i`: Specify the key file and pass the parameters directly to ssh use
`-l`: Limit network speed to Kbit/s For the unit
`-C`: Allow compression
`-1,-2`: mandatory scp Command to use ssh1 or ssh2 agreement
`-4,-6`: use ipv4 or ipv6 addressing
Here is an example of the more common scp command.
1. Local file transfer to remote server
Command format:
scp test.txt root@192.168.1.1:/home/
Copy the test.txt file to the home folder under the target server (192.168.1.1).
2. Local folder transfer to remote server
Command format:
scp -r test root@192.168.1.1:/home/
Copy the entire test folder to the home folder under the target server.
3. Remote server file transfer to local
Command format:
scp root@192.168.1.1:/home/test.txt test
Copy the test.txt file in the home directory in the remote service to the local test directory
4. Copy the remote server folder locally
scp -r root@192.168.1.1:/home/test /Users/jjz
Copy the entire test directory in the home directory on the remote server to the local jjz directory
5. The scp command specifies the key file
scp test.txt root@192.168.1.1:/home/ -i ~/.ssh/id_rsa.1
The key file id_rsa. 1 is specified as the connection parameter for ssh. The default key file is not used.
Thank you for reading, I hope to help you, thank you for your support of this site!