1. Command function
CP: Copy a file or directory, the file exists will ask whether to overwrite
2. Command format
CP [Options] file or directory
3. Command parameters
-I: asking when overwriting
-r: Copy directory, recursive replication
-F: Forced replication
-P: Preserve file attributes and copy
--backup: Backing up files that exist
-A: equivalent to-PR
4. Command instances
Example 1: Interactive replication
[Email protected] ~]# Cp/etc/inittab.
[[email protected] ~]# ls
Anaconda-ks.cfg Desktop file1 file2 gg inittab install.log install.log.syslog
[Email protected] ~]# cp-i/etc/inittab.
Cp:overwrite './inittab '? Yes
Example 2: Copy directory, recursive replication
[Email protected] ~]# cp-r/etc/.
[[email protected] ~]# ls
Anaconda-ks.cfg etc file2 Inittab Install.log.syslog
Desktop file1 GG Install.log
Example 3: Forced replication
[Email protected] ~]# \cp-f/etc/inittab.
[Email protected] ~]# cp-i/etc/inittab.
Cp:overwrite './inittab '? Yes
[Email protected] ~]# \cp-f/etc/inittab. #因为cp是一个别名, the command itself can be used with a backslash
[Email protected] ~]#
Example 4: Preserve file attributes and copy
[email protected] ~]# LL
Total 72
-RW-------1 root root 1259 Nov 19:18 anaconda-ks.cfg
drwx------2 root root 4096 Nov 19:25 Desktop
-rw-r--r--1 root root 0 Dec 17:07 file1
-rw-r--r--1 root root 0 Dec 17:12 file2
Drwxr-xr-x 2 root root 4096 Dec 16:43 GG
-rw-r--r--1 root root 39302 Nov 19:17 Install.log
-rw-r--r--1 root root 4062 Nov 19:17 install.log.syslog
-R--------1 xiaomo root 976 Nov 19:17 Shadow
[email protected] ~]# CP shadow/tmp/
[Email protected] ~]# ll/tmp/
Total 16
drwx------2 root root 4096 Nov 19:45 ksocket-root
drwx------2 root root 4096 Nov 19:45 orbit-root
-R--------1 root root 976 Dec 18:18 Shadow
drwx------2 root root 4096 Nov 19:44 ssh-rtxmsp5661
[Email protected] ~]# cp-p shadow/tmp/
Cp:overwrite '/tmp/shadow '? Yes
[Email protected] ~]# ll/tmp/
Total 16
drwx------2 root root 4096 Nov 19:45 ksocket-root
drwx------2 root root 4096 Nov 19:45 orbit-root
-R--------1 xiaomo root 976 Nov 19:17 Shadow
drwx------2 root root 4096 Nov 19:44 ssh-rtxmsp5661
Example 5: Backing up files that exist
[Email protected] ~]# cp-p--backup shadow/tmp/
Cp:overwrite '/tmp/shadow '? Yes
[Email protected] ~]# ll/tmp/
Total 20
drwx------2 root root 4096 Nov 19:45 ksocket-root
drwx------2 root root 4096 Nov 19:45 orbit-root
-R--------1 xiaomo root 976 Nov 19:17 Shadow
-R--------1 xiaomo root 976 Nov 19:17 shadow~
drwx------2 root root 4096 Nov 19:44 ssh-rtxmsp5661
Example 6: equivalent to-PR
[email protected] ~]# LL
Total 72
-RW-------1 root root 1259 Nov 19:18 anaconda-ks.cfg
drwx------2 root root 4096 Nov 19:25 Desktop
-rw-r--r--1 root root 0 Dec 17:07 file1
-rw-r--r--1 root root 0 Dec 17:12 file2
Drwxr-xr-x 2 root root 4096 Dec 16:43 GG
-rw-r--r--1 root root 39302 Nov 19:17 Install.log
-rw-r--r--1 root root 4062 Nov 19:17 install.log.syslog
-R--------1 xiaomo root 976 Nov 19:17 Shadow
[Email protected] ~]# cp-a shadow/tmp/
[Email protected] ~]# ll/tmp/
Total 16
drwx------2 root root 4096 Nov 19:45 ksocket-root
drwx------2 root root 4096 Nov 19:45 orbit-root
-R--------1 xiaomo root 976 Nov 19:17 Shadow
drwx------2 root root 4096 Nov 19:44 ssh-rtxmsp5661
This article is from the "cold-blooded Killer" blog, please be sure to keep this source http://deathkiller.blog.51cto.com/9130248/1592337
CP of Common Linux commands