Linux中的cp命令

cp命令用来复制文件或者目录

命令格式:

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

命令功能:
将源文件复制到目标文件,或者将多个源文件复制到目标目录

命令实例:

(1)

复制单个文件到目标目录,文件在目标目录中不存在

[root@centos65 testorder]# ll
total 4
drwxr-xr-x 4 root root 31 Aug 19 09:54 test001
-rw-r--r-- 1 root root 18 Aug 19 09:58 test003.log
-rw-r--r-- 1 root root  0 Aug 19 09:57 test003.log~
[root@centos65 testorder]# 
[root@centos65 testorder]# 
[root@centos65 testorder]# cp test003.log test001
[root@centos65 testorder]# 
[root@centos65 testorder]# 
[root@centos65 testorder]# ll
total 4
drwxr-xr-x 4 root root 49 Aug 20 08:36 test001
-rw-r--r-- 1 root root 18 Aug 19 09:58 test003.log
-rw-r--r-- 1 root root  0 Aug 19 09:57 test003.log~
[root@centos65 testorder]# 
[root@centos65 testorder]# 
[root@centos65 testorder]# 
[root@centos65 testorder]# cd test001
[root@centos65 test001]# ll
total 4
drwxr-xr-x 2 root root  6 Aug 19 09:55 test
drwxr-xr-x 2 root root 78 Aug 19 09:55 test001
-rw-r--r-- 1 root root 18 Aug 20 08:36 test003.log

(2)目标文件存在的时候,会询问是否覆盖

[root@centos65 testorder]# cd test001
[root@centos65 test001]# ll
total 4
drwxr-xr-x 2 root root  6 Aug 19 09:55 test
drwxr-xr-x 2 root root 78 Aug 19 09:55 test001
-rw-r--r-- 1 root root 18 Aug 20 08:36 test003.log
[root@centos65 test001]# 
[root@centos65 test001]# cp test003.log test001
cp: overwrite `test001/test003.log'? y

(3)复制整个目录

[root@centos65 test001]# ll
total 4
drwxr-xr-x 2 root root  6 Aug 19 09:55 test
drwxr-xr-x 2 root root 78 Aug 19 09:55 test001
-rw-r--r-- 1 root root 18 Aug 20 08:36 test003.log
[root@centos65 test001]# 
[root@centos65 test001]# 
[root@centos65 test001]# 
[root@centos65 test001]# cp -a test001 test
[root@centos65 test001]# 
[root@centos65 test001]# 
[root@centos65 test001]# cd test
[root@centos65 test]# ll
total 0
drwxr-xr-x 2 root root 78 Aug 19 09:55 test001
[root@centos65 test]# cd ../test001
[root@centos65 test001]# ll
total 8
-rw-r--r-- 1 root root 40 Aug 19 09:24 test001.log
-rw-r--r-- 1 root root  0 Aug 19 09:36 test002.log
-rw-r--r-- 1 root root 18 Aug 20 08:37 test003.log
-rw-r--r-- 1 root root  0 Aug 19 09:36 test004.log

(4)建立一个连接档(相当于windows的快捷方式)

[root@centos65 test]# ll
total 8
drwxr-xr-x 2 root root 78 Aug 19 09:55 test001
-rw-r--r-- 1 root root 40 Aug 20 08:47 test001.log
drwxr-xr-x 2 root root  6 Aug 20 08:43 test002
-rw-r--r-- 1 root root  0 Aug 20 08:47 test002.log
-rw-r--r-- 1 root root 18 Aug 20 08:47 test003.log
-rw-r--r-- 1 root root  0 Aug 20 08:47 test004.log
[root@centos65 test]# 
[root@centos65 test]# 
[root@centos65 test]# cp -s test001.log test001_link.log
[root@centos65 test]# ll
total 8
drwxr-xr-x 2 root root 78 Aug 19 09:55 test001
lrwxrwxrwx 1 root root 11 Aug 20 08:50 test001_link.log -> test001.log
-rw-r--r-- 1 root root 40 Aug 20 08:47 test001.log
drwxr-xr-x 2 root root  6 Aug 20 08:43 test002
-rw-r--r-- 1 root root  0 Aug 20 08:47 test002.log
-rw-r--r-- 1 root root 18 Aug 20 08:47 test003.log
-rw-r--r-- 1 root root  0 Aug 20 08:47 test004.log


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值