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

cp (copy files and directories)

man cp 查看更多命令

cp  [-aifprud] source target
        -a : 相当于 -pdr
        -d : 源文件为链接文件,则复制过去也是链接文件,而不是源文档
        -i : 复制的文件的,覆盖文件的时候,提示
        -f : 强制,如果目标文件已经存在且无法开启,则移除后在尝试
        -p : 连同档案的属性一起复制过去,而非使用默认的属性
        -r : 递归复制,用于复制目录
        -u : 如果目标文件已近存在,则目标文件要比源文件要旧的时候在复制。
cp 文件 目标目录 只是复制文件
root@guofeng  ~
# ll
total 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.txt
drwxr-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.java
drwxr-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.syslog
drwxr-xr-x  2 root root  4096 Jun 11 23:19 java
-rw-r--r--  1 root root     0 Jun 12  2016 mm.txt
drwxr-xr-x  2 root root  4096 Jun 11 23:19 test
-rw-r--r--  1 root root     0 Jun 11 20:06 test.txt
drwxr-xr-x  2 root root  4096 Jun 11 23:20 web

root@guofeng  ~
# cp b.txt test

root@guofeng  ~
# ll
total 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.txt
drwxr-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.java
drwxr-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.syslog
drwxr-xr-x  2 root root  4096 Jun 11 23:19 java
-rw-r--r--  1 root root     0 Jun 12  2016 mm.txt
drwxr-xr-x  2 root root  4096 Jun 11 23:21 test
-rw-r--r--  1 root root     0 Jun 11 20:06 test.txt
drwxr-xr-x  2 root root  4096 Jun 11 23:20 web

root@guofeng  ~
# cd test

root@guofeng  ~/test
# ll
total 0
-rw-r--r-- 1 root root 0 Jun 11 23:21 b.txt

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

root@guofeng  ~
# ll
total 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.txt
drwxr-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.java
drwxr-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.syslog
drwxr-xr-x  2 root root  4096 Jun 11 23:19 java
-rw-r--r--  1 root root     0 Jun 12  2016 mm.txt
drwxr-xr-x  2 root root  4096 Jun 11 23:21 test
-rw-r--r--  1 root root     0 Jun 11 20:06 test.txt
drwxr-xr-x  2 root root  4096 Jun 11 23:20 web

root@guofeng  ~
# cp -r css html/

root@guofeng  ~
# ls -l html
total 4
drwxr-xr-x 2 root root 4096 Jun 11 23:32 css

root@guofeng  ~
# cp -a test html/

root@guofeng  ~
# ls -l html
total 8
drwxr-xr-x 2 root root 4096 Jun 11 23:32 css
drwxr-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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值