Linux Commands-CP: Copy Files and directories

Source: Internet
Author: User

Command format

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

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

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

Command parameters

-A,--archive
Copy files and directories and their properties. Includes ownership and permissions.

--backup[=control]
Create a backup of each existing target file.

-B
Similar to the--backup option, but does not accept parameters.

-F,--force
If a target file that already exists cannot be opened, remove it and try again (this option is redundant when the-n option is used).

-I.,--interactive
Prompts the user for confirmation before overwriting an existing file.

-L,--link
Link files without copying them.

-N,--no-clobber
Files that already exist are not overwritten (this option overrides the previous-i option).

-R,-R,--recursive
Recursively replicates the directory and its contents. This option is required for copying directories (or-a option).

-S,--symbolic-link
Only symbolic links are created and not copied.

-S,--suffix=suffix
Specify the suffix of the backup file yourself.

-T,--no-target-directory
Treat the target directory as a normal file.

-U,--update
When copying files from one directory to another, only files that do not exist in the destination directory or update files for the corresponding files in the destination directory are copied.

-V,--verbose
An informational message is displayed when a file is copied.

--help
Displays help information.

--version
Displays version information.

Instance

A) Copy the file F1 to F2. If F2 exists, it will be overwritten with F1 content. If F2 does not exist, the F2 is created.

Date > F1 CP F1 F2 CMP F1 F2

b) If the target file exists, indicate whether to overwrite it.

Cp-i F1 F2

c) Copy the file F1 and F2 to the directory D1, D1 must already exist.

mkdir D1 CP F1 F2 d1 ls d1F1  F2

d) Copy all the files in the D1 to D2 by using a wildcard character. The D2 must be already there.

mkdir D2 CP d1/* D2 ls D2F1  F2

e) Copy the D1 directory (and its contents) into the D3 directory. If D3 does not exist, the D3 is created and contains the same content as the D1 directory.

mkdir D3 cp-r D1 D3 ls-r D3d3:d1d3/d1:f1  cp-r d1 d4ls-r d4d4:f1  f2

Linux Commands-CP: Copy Files and directories

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.