"Linux" CP command

Source: Internet
Author: User

Use

CP can also create shortcuts in addition to the copy function

Full Name

CP is all called copy

Parameters

-A: equivalent to specifying parameters at the same time PDR

-D: If the file is a link file's property (link files), the linked file property is copied instead of the file itself

-F: Mandatory meaning (Force), if the target file already exists and cannot be opened, then try again after removing

-I: If the target file exists, the action will be asked before overwriting

-L: Link to a hard link instead of copying the file itself

-P: Copied along with the default properties of the archive, not using default properties

-R: Recursive continuous Replication for directory replication behavior

-S: Copy as a symbolic link file, which is a shortcut

-U: Update if destination is older than source

Case

Example one: Copy the. BASHRC from the home directory to/TMP under root, and modify the name to BASHRC, and use the I parameter

[email protected] ~]# CP. BASHRC/TMP/BASHRC Copy the. BASHRC from the home directory to/TMP, and modify the name to BASHRC

[email protected] ~]# cp-i. BASHRC/TMP/BASHRC
CP: Do you want to overwrite "/TMP/BASHRC"? y N is not covered, Y is overlay

Example two: Transform the directory to/TMP and copy the/etc/host.conf file to the directory

Before copying:

[email protected] tmp]# ls-l/var/log/btmp View file properties
-RW-------. 1 root utmp 768 August 6 21:52/var/log/btmp

Copy:

[email protected] tmp]# cp/var/log/btmp. Copy file btmp to current directory

After copying:

[email protected] tmp]# ls-l btmp View the copied file properties
-RW-------. 1 root root 768 August 7 22:21 btmp

We can see from the Green Mark section that the obvious change

To add a parameter copy:

[email protected] tmp]# cp-a/var/log/btmp.
CP: Do you want to overwrite "./btmp"? Y

[email protected] tmp]# ls-l btmp
-RW-------. 1 root utmp 768 August 6 21:52 btmp

Example three: Copy all the contents of the/etc/directory to/tmp

[email protected] tmp]# cp/etc/tmp
CP: Skip Directory "/etc"

In this case, you need to add the parameter R to replicate

[email protected] tmp]# cp-r/etc/tmp can also use a parameter (cp-a/etc/tmp )

Example four: Creating a Connection file (shortcut)

[email protected] tmp]# cp-s BASHRC Bashrc_link
[Email protected] tmp]#
ls-l bashrc*
-rw-r--r--. 1 root root 176 August 7 22:08 BASHRC
lrwxrwxrwx. 1 root root 6 August 7 22:39 bashrc_link–> BASHRC bashrc_link as Shortcut

Example five: If ~/.BASHRC is newer than TMP/BARSHRC, copy it.

[email protected] tmp]# cp-u ~/.BASHRC /TMP/BASHRC

Example SIX: see the D parameter action by copying a shortcut

[email protected] tmp]# CP bashrc_link bashrc_link1 generic copy, without parameter d, the source file is copied
[email protected] tmp]# cp-d Bashrc_link bashrc_link2 copied the shortcut
[email protected] tmp]# ls-l bashrc*
-rw-r--r--. 1 root root 176 August 7 22:08 BASHRC
lrwxrwxrwx. 1 root root 6 August 7 22:39 bashrc_link-BASHRC
-rw-r--r--. 1 root root 176 August 7 22:47 Bashrc_link1
lrwxrwxrwx. 1 root root 6 August 7 22:47 bashrc_link2-BASHRC

Example seven: Multiple data files are copied to the same directory

For example, there is a file 1.txt,2.txt,3.txt under directory TMP (3 files are empty pieces)

[email protected] tmp]# cp/tmp/1.txt/tmp/2.txt/tmp/3.txt/usr/local/sbin/
[Email protected] tmp]#
cd/usr/local/sbin/
[email protected] sbin]# LL
Total dosage

-rw-r--r--. 1 root root 0 August 7 22:53 1.txt
-rw-r--r--. 1 root root 0 August 7 22:53 2.txt
-rw-r--r--. 1 root root 0 August 7 22:53 3.txt

We can see that the files have been successfully copied


"Linux" CP command

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.