每天一命令(7)cp (copy files and directories)

来源:互联网 发布:陈少杰 西安 网络直播 编辑:程序博客网 时间:2024/06/12 22:12

cp (copy files and directories)

man cp 查看更多命令

cp  [-aifprud] source target        -a : 相当于 -pdr        -d : 源文件为链接文件,则复制过去也是链接文件,而不是源文档        -i : 复制的文件的,覆盖文件的时候,提示        -f : 强制,如果目标文件已经存在且无法开启,则移除后在尝试        -p : 连同档案的属性一起复制过去,而非使用默认的属性        -r : 递归复制,用于复制目录        -u : 如果目标文件已近存在,则目标文件要比源文件要旧的时候在复制。

cp 文件 目标目录 只是复制文件

root@guofeng  ~# lltotal 84-rw-------. 1 root root  2404 Nov  8  2014 anaconda-ks.cfg-rw-r--r--  1 root root     0 Jun  6 18:47 b-ba-c.txt-rw-r--r--  1 root root     0 Jun 11 20:48 b.txtdrwxr-xr-x  2 root root  4096 Jun 11 23:19 css-rw-r--r--  1 root root   868 Jun  9 21:06 dump.rdb-rw-r--r--  1 root root     0 May 17 07:00 EOF-rw-r--r--  1 root root     0 Jun 11 23:20 Hello.javadrwxr-xr-x  2 root root  4096 Jun 11 23:20 html-rw-r--r--  1 root root     0 Jun 11 23:20 index.css-rw-r--r--. 1 root root 39004 Nov  8  2014 install.log-rw-r--r--. 1 root root  9154 Nov  8  2014 install.log.syslogdrwxr-xr-x  2 root root  4096 Jun 11 23:19 java-rw-r--r--  1 root root     0 Jun 12  2016 mm.txtdrwxr-xr-x  2 root root  4096 Jun 11 23:19 test-rw-r--r--  1 root root     0 Jun 11 20:06 test.txtdrwxr-xr-x  2 root root  4096 Jun 11 23:20 webroot@guofeng  ~# cp b.txt testroot@guofeng  ~# lltotal 84-rw-------. 1 root root  2404 Nov  8  2014 anaconda-ks.cfg-rw-r--r--  1 root root     0 Jun  6 18:47 b-ba-c.txt-rw-r--r--  1 root root     0 Jun 11 20:48 b.txtdrwxr-xr-x  2 root root  4096 Jun 11 23:19 css-rw-r--r--  1 root root   868 Jun  9 21:06 dump.rdb-rw-r--r--  1 root root     0 May 17 07:00 EOF-rw-r--r--  1 root root     0 Jun 11 23:20 Hello.javadrwxr-xr-x  2 root root  4096 Jun 11 23:20 html-rw-r--r--  1 root root     0 Jun 11 23:20 index.css-rw-r--r--. 1 root root 39004 Nov  8  2014 install.log-rw-r--r--. 1 root root  9154 Nov  8  2014 install.log.syslogdrwxr-xr-x  2 root root  4096 Jun 11 23:19 java-rw-r--r--  1 root root     0 Jun 12  2016 mm.txtdrwxr-xr-x  2 root root  4096 Jun 11 23:21 test-rw-r--r--  1 root root     0 Jun 11 20:06 test.txtdrwxr-xr-x  2 root root  4096 Jun 11 23:20 webroot@guofeng  ~# cd testroot@guofeng  ~/test# lltotal 0-rw-r--r-- 1 root root 0 Jun 11 23:21 b.txt

cp -r 源码目录 目标目录 复制目录 cp -a

root@guofeng  ~# lltotal 84-rw-------. 1 root root  2404 Nov  8  2014 anaconda-ks.cfg-rw-r--r--  1 root root     0 Jun  6 18:47 b-ba-c.txt-rw-r--r--  1 root root     0 Jun 11 20:48 b.txtdrwxr-xr-x  2 root root  4096 Jun 11 23:19 css-rw-r--r--  1 root root   868 Jun  9 21:06 dump.rdb-rw-r--r--  1 root root     0 May 17 07:00 EOF-rw-r--r--  1 root root     0 Jun 11 23:20 Hello.javadrwxr-xr-x  3 root root  4096 Jun 11 23:32 html-rw-r--r--  1 root root     0 Jun 11 23:20 index.css-rw-r--r--. 1 root root 39004 Nov  8  2014 install.log-rw-r--r--. 1 root root  9154 Nov  8  2014 install.log.syslogdrwxr-xr-x  2 root root  4096 Jun 11 23:19 java-rw-r--r--  1 root root     0 Jun 12  2016 mm.txtdrwxr-xr-x  2 root root  4096 Jun 11 23:21 test-rw-r--r--  1 root root     0 Jun 11 20:06 test.txtdrwxr-xr-x  2 root root  4096 Jun 11 23:20 webroot@guofeng  ~# cp -r css html/root@guofeng  ~# ls -l htmltotal 4drwxr-xr-x 2 root root 4096 Jun 11 23:32 cssroot@guofeng  ~# cp -a test html/root@guofeng  ~# ls -l htmltotal 8drwxr-xr-x 2 root root 4096 Jun 11 23:32 cssdrwxr-xr-x 2 root root 4096 Jun 11 23:21 test

复制文件,如果有文件,提示是否覆盖 cp -i

root@guofeng  ~# cp -i Hello.java web/root@guofeng  ~# cp -i Hello.java web/cp: overwrite `web/Hello.java'? y
0 0
原创粉丝点击