The Linux CP command always gives

Source: Internet
Author: User

Describe:

The CP command is used to copy one or more source files or directories to a specified destination file or directory. It can copy a single source file into a specific file with a specified file name or a directory that already exists. The CP command also supports copying multiple files at once, and when copying multiple files at a time, the target file parameter must be a directory that already exists, or an error will occur.

Description

CP command:cp-copy files and directories

Usage: cp source file target file;

Syntax format:

CP [OPTION] ... [-T] SOURCE DEST

CP [OPTION] ... SOURCE ... DIRECTORY

CP [OPTION] ...-t DIRECTORY SOURCE ...

Single source copy: CP [OPTION] ... [-T] SOURCE DEST

if the dest does not exist, the directory will be created beforehand and the data of the copied file is streamed to dest

Multi-source replication: CP [OPTION] ... SOURCE ... DIRECTORY

CP [OPTION] ...-t DIRECTORY SOURCE ...

Common options:

-I: interactive replication, which indicates whether to overwrite before copying

-F: force overwrite target file

-r,r: recursively replicating directories

-D: Copy the symbolic link file itself instead of the source file it points to

-A: for archive Implementation

--preserve=[attr_list]

Mode: Permissions

Timestamps: time stamp

Xattr: Extended Properties

Links: Symbolic Links

All: Appeal All Properties

-P: equivalent to--preserv=mode,ownership,timestamp

-V: Display procedure

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/26/wKioL1ea_aCwvrVmAABa2HVtTnI963.png "title=" QQ picture 20160729145455.png "alt=" Wkiol1ea_acwvrvmaaba2hvttni963.png "/>


Example:

1. copy file A to/TMP under current directory, file a pre-existing

[[email protected] ~]# CP a/tmp[[email protected] ~]# Ls/tmpa KS-SCRIPT-MVRGLM ks-script-mvrglm.log yum.log

2, copy the current directory under file A, file B to/tmp/e, file e pre-existing:

[email protected] ~]# cp a/tmp/ecp:overwrite '/tmp/e '? Y

3, copy the current directory under Files A to/tmp/a, the directory pre-existing:

[[email protected] ~]# CP a/tmp/a[[email protected] ~]# LS/TMP/AA

4, copy the file under the current directory, A, B to G, G does not exist beforehand:

[[email protected] ~]# CP a b gcp:target ' G ' is not a directory

5, copy the files under the current directory A, B to/tmp/z, file Z pre-existing:

[[email protected] ~]# CP a b C d/tmp/zcp:target '/tmp/z ' is not a directory

6. Copy the file under the current directory, A, b to/tmp/b, and the pre-existing directory:

[[email protected] ~]# CP a b/tmp/b[[email protected] ~]# ls/tmp/ba b

7, copy the directory under the current directory A to/tmp:

[[email protected] ~]# cp-r a/tmp[[email protected] ~]# Ls/tmp/ac D

8, copy the current directory under directory A to/tmp/a, file a pre-existing:

[[email protected] ~]# cp-r a/tmp/acp:cannot overwrite non-directory '/tmp/a ' with directory ' A '

9, copy the directory under the current directory A to/tmp:

[[email protected] ~]# cp-r a/tmp[[email protected] ~]# Ls/tmp/ac D


Exercises:

1, using the alias command Baketc, the daily /etc/ directory of all files, backup to /testdir/ under the new directory under a separate,

and requires that the new directory be formatted as BACKUPYYYY-MM-DD , the backup process is visible

# alias Baketc= ' cp-arv/etc//testdir/backup$ (date +%f) '


2, First create /testdir/rootdir directory, and then copy /root all the next files into that directory and require that the original permissions be retained

# CP--preserve=mode-r/root//TESTDIR/ROOTCP


Concluding remarks:    

The above content is my summary of CP command, because I beginner Linux, to this command understanding and understanding is not comprehensive and in-depth, inevitably there will be omissions, hope you pass the talent of many advice, greatly appreciated!

The Linux CP command always gives

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.