Linux Basic Command Learning CP (4)

Source: Internet
Author: User

Cp

1. Command Format

Usage:

CP [Options ] ... [-t] source purpose

or: cp [Options ] ... Source... Catalogue

or: cp [Options] ...-t directory source ...

2. Command function

Copy the source file to the destination file, or copy multiple source files to the destination directory .

3. command parameters and instances

-A,--archive equals-dr--preserve=all

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

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

--copy-contents in recursive processing is to copy special file contents

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

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

There is no need to select this option)

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

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

-L,--link link files without copying

-L,--dereference always follow the symbolic link

-N,--no-clobber do not overwrite existing files (invalidates the previous-i option)

-P,--no-dereference does not follow the symbolic link in the source file

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

the--preserve[= property list retains the specified property (default: Mode, ownership, timestamp), as the result may persist attached properties: environment, links, xattr, etc.

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

#######################################################################

Instance one: Copy a single file to the destination directory, the file does not exist in the destination file

Cp/data/a.txt/test

[Email protected] data]# cp/data/a.txt/test[[email protected] data]# ll/testtotal 28drwxr-xr-x. 2 root root 4096 Nov 05:12 a-rw-r--r--. 1 root root 05:26 a.txtdrwxr-xr-x. 2 root root 4096 Nov 05:12 bdrwxr-xr-x. 2 root root 4096 Nov 05:12 cdrwxr-xr-x. 3 root root 4096 Nov 05:14 test1drwxr-xr-x. 5 root root 4096 Nov 05:14 test2drwxr-xr-x. 5 root root 4096 Nov 05:14 Try[[email protected] data]#


Instance two: When the target file is present, it asks whether to overwrite

Command:

CP /data/a.txt/test/a.txt

[Email protected] data]# cp/data/a.txt/test/a.txtcp:overwrite '/test/a.txt '?


Example three: Copying the entire directory

command: cp-a/data/test

[Email protected] data]# cp-a/data/test[[email protected] data]# ll/testtotal 32drwxr-xr-x.  2 root root 4096 Nov 05:12 a-rw-r--r--.  1 root root 05:26 a.txtdrwxr-xr-x.  2 root root 4096 Nov 05:12 bdrwxr-xr-x. 2 root root 4096 Nov 05:12 cdrwxr-xr-x.  Root root 4096 Nov 05:09 datadrwxr-xr-x.  3 root root 4096 Nov 05:14 test1drwxr-xr-x.  5 root root 4096 Nov 05:14 test2drwxr-xr-x. 5 root root 4096 Nov 05:14 Try[[email protected] data]#


Example four: Copy the Log.log to create a link file Log_link.log

Command:

cp-s a.txt Link_a.txt

[[email protected] data]# cp -s a.txt link_a.txt[[email protected]  Data]# lltotal 52-rw-r--r--.  1 root root    0 nov 14   2012 admin.log-rw-r--r--.  1 root root   15 nov 13  04:09 a.txt-rw-r--r--.  1 root root   31 nov 13 04:09  b.txt-rw-r--r--.  1 root root   81 Nov 13 04:09  C.txtdrwxr-xr-x. 2 root root 4096 nov 13 04:58 dcpdrwxr-xr-x. 2  root root 4096 nov 13 03:49 dongdrwxr-xr-x. 2 root root  4096 nov 13 05:03 jimlrwxrwxrwx. 1 root root    5  Nov 13 05:38 link_a.txt -> a.txtdrwxr-xr-x. 2 root root  4096 nov 13 05:03&nbSp;lucy-rw-r--r--.  1 root root    0 Nov 13 04:13  Pbc.bmpdrwxrwxrwx. 2 root root 4096 nov 13 05:09 superdrwxr-xr-x.  3 root root 4096 nov 13 05:03 teacherdrwxr-xr-x. 2 root  root 4096 nov 13 05:06 teamdrwxr-xr-x. 2 root root 4096  Nov 13 05:04 test1drwxr-xr-x. 3 root root 4096 Nov 13  05:06 test2-rw-r--r--.  1 root root    0 nov 13 04:48  test.txtdrwxr-xr-x. 2 root root 4096 nov 13 04:08 you[[email  protected] data]#



This article is from the "Qin Xian son" blog, please make sure to keep this source http://youdong.blog.51cto.com/3562886/1718142

Linux Basic Command Learning CP (4)

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.