How to use CP and SCP commands in Linux

Source: Internet
Author: User
Tags file copy ftp ftp client ssh scp command

Linux gives us two commands for file copy, one for CP and one for SCP, but they are slightly different.

CP---is mainly used to copy files back and forth between different directories on the same computer

SCP---Primarily to copy files back and forth between different Linux systems

For specific use of CP:

Command basic format:

CP [OPTIONS] source DEST---From source path copy file to destination path

CP [OPTIONS] SOURCE ... Directory---Copy multiple source files to a specified directory (multiple source files are separated by spaces)

OPTIONS:

-a same AS-DPR as far as possible the source file status, permissions and other materials are reproduced according to the original, and is recursive copy;

-R means recursive copy, if the source contains a directory name, then the directory files are also copied to the destination;

-F indicates force, if the destination already has the same file name of the file exists, then before copying to delete 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/

Specific uses for the SCP:

There are 3 common ways to copy files between different Linux types:

The first is FTP, which is one of the Linux installation FTP Server, this can be in another machine using FTP client program for file copy.

The second approach is to use the Samba service, similar to the Windows file copy of the way to operate, more concise and convenient.

The third way is to use the SCP command for file copying.

The SCP is a security file copy, based on SSH login.

Command basic format:

SCP [OPTIONS] File_source File_target

OPTIONS:

-V is the same as the-V meaning in most Linux commands, and is used to show progress. Can be used to view connection, authentication, or configuration errors

-C Enable Compression option

-P Select the port. Note-P has been used by RCP

Replicate from local to remote

Scp/home/daisy/full.tar.gz Root@172.19.2.75:/home/root (then prompts you to enter the login password for the other 172.19.2.75 host's root user, and then it starts copy), Copy directory plus parameter-r

From remote replication to local

SCP root@/172.19.2.75:/home/root/full.tar.gz/home/daisy/full.tar.gz

The following are supplementary:

Command: CP

Use Rights: All users

How to use:

CP [Options] Source Dest

CP [options] source ... directory

Note: Copy one file to another file or copy several files to another directory.

The meter

-A as far as possible, file status, permissions and other information are reproduced as the original.

-R If the source contains a directory name, then the directory of the files are also copied to the destination.

-F If a file with the same file name exists at the destination, delete it before copying it.

Example:

Copy the file AAA (already exists) and name it BBB:

CP AAA BBB

Copy all C language programs to the finished subdirectory:

CP *.c finished

Command: SCP

There are 3 common ways to copy files between different Linux types:

The first is FTP, which is one of the Linux installation FTP Server, this can be another use of FTP client program for file copy.

The second approach is to use the Samba service, similar to the Windows file copy of the way to operate, more concise and convenient.

The third way is to use the SCP command for file copying.

The SCP is a security file copy, based on SSH login. Easy to operate, such as to the current one file copy to a remote other host, you can command the following.

Scp/home/daisy/full.tar.gz Root@172.19.2.75:/home/root

You will then be prompted to enter the login password for the other 172.19.2.75 host's root user, and then copy it.

If you want to reverse the operation, it is also easy to copy the files from the remote host to the current system.

Linux CP/SCP Command +SCP command Detailed (Turn)-Linmaogan-Lone wood ★ Not forest SCP root@/full.tar.gz 172.19.2.75:/home/root/full.tar.gz home/daisy/ Full.tar.gz

Linux's SCP commands allow you to copy files and directories between Linux;

==================

SCP command

==================

The SCP can replicate files between 2 Linux hosts;

Command basic format:

SCP [Optional parameters] File_source File_target

======

Replicate from local to remote

======

* Copy files:

* Command format:

SCP Local_file Remote_username@remote_ip:remote_folder

Or

SCP Local_file Remote_username@remote_ip:remote_file

Or

SCP Local_file Remote_ip:remote_folder

Or

SCP Local_file Remote_ip:remote_file

1th, 2 specified the user name, the command needs to enter the password after the execution, the 1th specified only the remote directory, the file name unchanged, the 2nd specified the filename;

3rd, 4 did not specify the user name, the command needs to enter the user name and password, the 3rd specified only a remote directory, the file name unchanged, the 4th specified the filename;

Example

Scp/home/space/music/1.mp3 Root@www.cumt.edu.cn:/home/root/others/music

Scp/home/space/music/1.mp3 Root@www.cumt.edu.cn:/home/root/others/music/001.mp3

Scp/home/space/music/1.mp3 Www.cumt.edu.cn:/home/root/others/music

Scp/home/space/music/1.mp3 Www.cumt.edu.cn:/home/root/others/music/001.mp3

* Copy directory:

* Command format:

Scp-r Local_folder Remote_username@remote_ip:remote_folder

Or

Scp-r Local_folder Remote_ip:remote_folder

The 1th specifies the user name, the command needs to enter the password after the execution;

The 2nd does not specify the user name, the command needs to enter the user name and password after execution;

Example

Scp-r/home/space/music/root@www.cumt.edu.cn:/home/root/others/

Scp-r/home/space/music/www.cumt.edu.cn:/home/root/others/

The above command copies the local music directory to the remote others directory, which is remotely available after replication. /others/music/Directory

======

From remote replication to local

======

From remote to local, as long as the following 2 parameters of the command will be copied from the local to the remote order can be replaced;

For example:

SCP Root@www.cumt.edu.cn:/home/root/others/music/home/space/music/1.mp3

Scp-r www.cumt.edu.cn:/home/root/others//home/space/music/

The simplest applications are as follows:

SCP Local username @IP address: filename 1 remote username @IP address: filename 2

[Local username @IP address:] You may need to enter the password for the remote user name without entering it.

Several parameters that may be useful:

-V is the same as the-V meaning in most Linux commands, and is used to show progress. Can be used to view connections, authentication, or configuration errors.

-C enables compression options.

-P Select the port. Note-P has been used by RCP.

-4 forcibly use IPV4 address.

-6 forcibly use IPV6 address.

Note two points:

1. If the remote server firewall has special restrictions, the SCP will go to the special port, specific port depending on the situation, the command format is as follows:

#scp-P 4588 remote@www.abc.com:/usr/local/sin.sh/home/administrator

2. Use the SCP to be aware of whether the user you are using has permission to read the appropriate files for the remote server.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.