Linux system Copy File/folder-CP command usage

Source: Internet
Author: User

Name: 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.
-A,--archive equals-dr--preserve=all

--backup[=control Create a backup for each existing target file

-B is similar to--backup but does not accept parameters

--copy-contents in recursive processing is the copying of special file contents

-D equals--no-dereference--preserve=links

-F,--force remove the target file if it cannot be opened and try again (when-n option

Does not need to be selected when it is present

-I,--interactive before overwriting (invalidates the previous-n option)

-H follow the command line symbolic link in the source file

-L,--link linked file without copying

-L,--dereference always follow symbolic links

-N,--no-clobber do not overwrite existing files (make the previous-I option invalid)

-P,--no-dereference does not follow symbolic links in source files

-P equals--preserve= mode, ownership, timestamp

The--preserve[= property list retains the specified property (default: Mode, ownership, timestamp), if

May retain additional properties: environment, links, xattr, etc.

-R, R,--recursive copy all items in directory and directory

Example:

Copying files, copying files only if the source file is newer than the destination file's modification time
Cp-u-V file1 file2

. copy file file1 to file File2
CP file1 File2

. interactively copy file file1 into a file file2
Cp-i file1 file2

Copy the file file1 to File2 because the destination file already exists, so specify the mode to use forced replication
Cp-f file1 file2

. copy directory Dir1 into a directory Dir2
Cp-r file1 file2

. Also copy files File1, file2, File3, and directory Dir1 to Dir2
Cp-r file1 file2 file3 dir1 dir2

. preserve file properties when copying
Cp-p a.txt tmp/

. Preserve the directory structure of files when replicating
Cp-p/var/tmp/a.txt./temp/

. Generate backup files when replicating
Cp-b a.txt tmp/

The backup file is generated when copying, and the tail-label ~1~ format
Cp-b-V T a.txt/tmp

. Specify the tail label of the backup file
Cp-b-S _bak a.txt/tmp

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.