Linux cp/scp command + scp command details, cpscp + scp command details

Source: Internet
Author: User
Tags scp command

Linux cp/scp command + scp command details, cpscp + scp command details

Name: cp

Permission: All Users

Usage:

Cp [options] source dest

Cp [options] source... directory

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

Count

-A tries its best to copy the file status, permissions, and other information as they are.

-R if the source contains the directory name, the files under the directory are also copied to the destination in sequence.

-F if the destination already has an archive with the same file name, delete it before copying.

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 three common methods to copy files between Linux:

The first is ftp, that is, one of the Linux installation ftp Server, so that another client program using ftp can be used 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. For example, to copy the current file to another remote host, you can run the following command.

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

Then, you will be prompted to enter the logon password of the root user of the other 172.19.2.75 host, and copy the password.

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

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

The scp command of linux can copy files and directories between linux;

============================
Scp command
============================
Scp can copy files between two linux Hosts;

Basic command format:
Scp [optional parameter] file_source file_target

======
Copy from local to remote
======
* Copy a file:
* 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

The user name is specified for the 1st and 2nd commands. After the command is executed, you need to enter the password. Only the remote directory is specified for the 1st command. The file name remains the same, and the file name is specified for the 1st command;
No user name is specified for the 3 and 4 commands. After the command is executed, enter the user name and password. Only the remote directory is specified for the 3rd commands. The file name remains the same and the file name is specified for the 4th commands;
* 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

1st user names are specified, and the password needs to be entered after the command is executed;
2nd user names are not specified. After the command is executed, enter the user name and password;
* 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, that is, there is a remote ../others/music/directory after the copy.


======
Copy from remote to local
======
From remote to local, you only need to replace the last two parameters of the local command to remote;

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 application is as follows:

Scp Local User Name @ IP Address: file name 1 remote user name @ IP Address: file name 2

[Local username @ IP Address:] You may not need to enter the password corresponding to the remote username.

Several useful parameters:

-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.

-4 Use the IPV4 address forcibly.

-6 Use IPV6 addresses forcibly.

 

Note:
1. If the remote server firewall has special restrictions, scp must go through the special port. The specific port used depends on the situation. The command format is as follows:
# Scp-p 4588 remote@www.abc.com:/usr/local/sin. sh/home/administrator
2. When using scp, pay attention to whether the user has the permission to read the corresponding files on the remote server.


The difference between the cp and scp commands in linux commands

Cp is a common file copy.
Scp is a copy of the local machine through ssh and other computers

Cp a.txt B .txt: Copy a.txt to B .txt.
Scp a.txt xxx@192.168.110.110:/home/xxx
Assign a.txt to the/home/xxx directory of the machine whose LAN ip address is 192.168.110.110

Linux scp command file

I read the scp man manual page and found that no parameters support skipping the same file, sorry
You should use scp to copy data on different hosts, but you can use scp to copy data to the target host first.
A directory, and then copy it to the final target directory through the/bin/cp command, because cp is in the system
The alias is used, so you need to use/bin/cp instead of cp because the alias contains the-I parameter.
If the same file is used, a prompt will always be displayed. If/bin/cp is used, no prompt will be displayed. Then you can use the-u parameter.
When the same file is used, the source file is updated only when it is newer than the target file. You do not prompt to skip the file directly for the same file.
Verify that all files in the target directory are up to date. For example
The current time is
Update time of all objects in the target directory:
Find dstdir-exec touch-t 201303251404 {}\;
/Bin/cp-avpu srcdir/* dstdir
Of course, if you have copied the file to the same server, you can also use shell scripts, which is more reliable, but the script is more complex.

Related Article

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.