recently learning to copy files in linux command CP, the learning record is as follows
CP [option] Source (source file) destination (destination file)CP [Options] Source1Source2 Source3Source4source5 ... directory
CP command can copy files or folders, can be followed by multiple source files, when there are multiple source files, the last parameter is the destination directory to be stored, if the destination directory does not exist, not the destination directory will be an error. As shown in the following:
[[email protected] ~]# ll
总用量 8
-rw-------. 1 root root 1585 4月 29 09:11 anaconda-ks.cfg
- RW - r -- r --. 1 root root 1633 4 month Span class= "lit" >29 17 : 03 initial - setup Span class= "pun" >- ks cfg
[[email protected] ~]# cp /etc/asound.conf /etc/bashrc anaconda-ks.cfg
cp: 目标"anaconda-ks.cfg" 不是目录
[[email protected] ~]# cp /etc/asound.conf /etc/bashrc tmp
cp: 目标"tmp" 不是目录
Here's a look at the option parameter:-A: Equivalent to-dr-d: If the file is a linked file, the linked file will be copied instead of the file itself-F: To force replication-L: The replication of the link, not the copy-P of the document itself, along with the properties of the document (permission, user, time), Instead of using the preset properties of the copy-r: Copy recursively, use the option-s: Copy as Symbolic link-u: Compare the source file with the destination file and copy it if there is an update
Here's a look at some examples:
Example one: Copy Test to Test_root
[[email protected] dream]# ll
总用量 0
- RW - RW - r --. 1 Dream dream 0 5 month Span class= "lit" >11 09 : 58 test
-rw-rw-r--. 1 dream dream 0 5月 11 09:58 test.log
[[email protected] dream]# cp test test_root
[[email protected] dream]# ll
总用量 0
-rw-rw-r--. 1 dream dream 0 5月 11 09:58 test
- RW - RW - r --. 1 Dream dream 0 5 month Span class= "lit" >11 09 : 58 test log
-rw-r--r--. 1 root root 0 5月 11 09:58 test_root
Example two: Copy the ETC directory to the./tmp directory
[[email protected] dream]# cp -r /etc/ ./tmp/
Example three:put/etc/Rc.local the link file to the current directory and keep the link without copying the file itself
[[email protected] dream]# cp /etc/rc.local ./
[[email protected] dream]# ll
总用量 4
- RW - r -- r --. 1 root root 473 5 month Span class= "lit" >11 10 : 11 RC local
[[email protected] dream]# cp -d /etc/rc.local ./
[[email protected] dream]# ll
总用量 0
lrwxrwxrwx. 1 root root 13 5月 11 10:13 rc.local -> rc.d/rc.local
After reading the above examples, we can see that the properties of the destination file will change with the execution of the current command when the file is copied, and if you need to preserve the original property, you can use the-P option parameter
[[email protected] dream]# ll
总用量 0
-rw-rw-r--. 1 dream dream 0 5月 11 09:58 test
[[email protected] dream]# cp -p test ./test.tmp
[[email protected] dream]# ll
总用量 0
- RW - RW - r --. 1 Dream dream 0 5 month Span class= "lit" >11 09 : 58 test
-rw-rw-r--. 1 dream dream 0 5月 11 09:58 test.tmp
Summary: The CP command copies the file when it is associated with the command's executor; When you want to copy multiple files, the last parameter must be the directory
Linux learns a command's CP command every day