Linux命令(7):cp

功能说明:

        将源文件复制至目标文件,或将多个源文件复制至目标目录。

命令格式:

用法:

   cp [选项]... [-T] 源 目的

       或:cp [选项]... 源... 目录

       或:cp [选项]... -t 目录 源...

命令参数:   

-a, --archive    等于-dR --preserve=all

    --backup[=CONTROL    为每个已存在的目标文件创建备份

-b                类似--backup 但不接受参数

   --copy-contents        在递归处理是复制特殊文件内容

-d                等于--no-dereference --preserve=links

-f, --force        如果目标文件无法打开则将其移除并重试(当 -n 选项

                    存在时则不需再选此项)

-i, --interactive        覆盖前询问(使前面的 -n 选项失效)

-H                跟随源文件中的命令行符号链接

-l, --link            链接文件而不复制

-L, --dereference   总是跟随符号链接

-n, --no-clobber   不要覆盖已存在的文件(使前面的 -i 选项失效)

-P, --no-dereference   不跟随源文件中的符号链接

-p                等于--preserve=模式,所有权,时间戳

    --preserve[=属性列表   保持指定的属性(默认:模式,所有权,时间戳),如果

               可能保持附加属性:环境、链接、xattr 等

-R, -r, --recursive  复制目录及目录内的所有项目

命令案例:

案例1、复制单个文件到目标目录

[root@oldboy ~]# ll
total 64
-rw-r--r--. 1 root root 39 Jul 29 22:13 12345
-rw-r--r--. 1 root root 0 Aug 1 07:29 6:20pm
-rw-r--r-- 1 root root 135 Aug 8 14:24 a.txt
-rw-------. 1 root root 1216 Jul 28 08:30 anaconda-ks.cfg
-rw-r--r--. 1 root root 5 Aug 2 21:33 b.txt
-rw-r--r--. 1 root root 27312 Jul 28 08:30 install.log
-rw-r--r--. 1 root root 7572 Jul 28 08:28 install.log.syslog
-rw-r--r--. 1 root root 0 Aug 1 18:39 oldboy.txt
lrwxrwxrwx. 1 root root 7 Aug 2 04:57 one.txt -> two.txt
drwxr-xr-x. 4 root root 4096 Aug 7 13:59 test
-rw-r--r-- 1 root root 79 Aug 8 12:02 two.txt
[root@oldboy ~]# cp oldboy.txt test
[root@oldboy ~]# ll test
total 8
drwxr-xr-x 4 root root 4096 Aug 7 14:11 km
drwxr-xr-x 2 root root 4096 Aug 7 13:53 kmmiao
-rw-r--r-- 1 root root 0 Aug 8 15:10 oldboy.txt
[root@oldboy ~]#

2、复制整个目录

[root@oldboy test]# ll
total 8
drwxr-xr-x 4 root root 4096 Aug 7 14:11 km
drwxr-xr-x 2 root root 4096 Aug 7 13:53 kmmiao
-rw-r--r-- 1 root root 0 Aug 8 15:10 oldboy.txt
[root@oldboy test]# cp -a km kmmiao
[root@oldboy test]# ll kmmiao
total 4
drwxr-xr-x 4 root root 4096 Aug 7 14:11 km
[root@oldboy test]#

3、创建软连接

[root@oldboy test]# cp -s oldboy.txt oldboyline.txt
[root@oldboy test]# ll
total 8
drwxr-xr-x 4 root root 4096 Aug 7 14:11 km
drwxr-xr-x 3 root root 4096 Aug 8 15:12 kmmiao
-rw-r--r-- 1 root root 0 Aug 8 15:10 oldboy.txt
lrwxrwxrwx 1 root root 10 Aug 8 15:18 oldboyline.txt -> oldboy.txt

 

 

 

 

posted @ 2014-08-08 15:19  Arvin Miao  阅读(173)  评论(0编辑  收藏  举报