2.11-cp命令

cp (copy) 复制

复制文件
复制/etc/passwd 到/tmp/文件夹 新建的passwd.txt 里面

[root@evan-01 ~]# cp /etc/passwd /tmp/passwd.txt
[root@evan-01 tmp]# ls -l
总用量 124
-rwx------. 1 root root    836 8月   8 2019 ks-script-R9kDZ_
-rwxr-xr-x. 1 root root 117656 8月   8 11:19 ls2
-rw-r--r--. 1 root root    846 8月   8 11:36 passwd.txt
drwx------. 3 root root     17 8月   8 2019 systemd-private-7125f715cce542ff8ebf692caabfdafa-chronyd.service-mKqSc7
drwx------. 3 root root     17 8月   8 2019 systemd-private-7125f715cce542ff8ebf692caabfdafa-vgauthd.service-OgNGdX
drwx------. 3 root root     17 8月   8 2019 systemd-private-7125f715cce542ff8ebf692caabfdafa-vmtoolsd.service-NlfJGP
-rw-------. 1 root root      0 8月   8 2019 yum.log
[root@evan-01 tmp]# 

复制目录
复制/tmp/evanlinux/ 到 /tmp/ 目录里面的新建的 evan 目录里面
用cp的时候,所有的目录都加上/

[root@evan-01 tmp]# mkdir -p evanlinux/one
[root@evan-01 tmp]# touch evanlinux/one/test.txt
[root@evan-01 tmp]# tree /tmp
/tmp
├── evanlinux
│      └── one
│          └── test.txt
├── ks-script-R9kDZ_
├── ls2
├── passwd.txt
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-chronyd.service-mKqSc7
│     └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vgauthd.service-OgNGdX
│     └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vmtoolsd.service-NlfJGP
│     └── tmp
│          └── vmware-root
└── yum.log

9 directories, 5 files
[root@evan-01 tmp]# cp -r evanlinux/  evan/
[root@evan-01 tmp]# tree /tmp              
/tmp
├── evan
│     └── one
│        └── test.txt
├── evanlinux
│     └── one
│        └── test.txt
├── ks-script-R9kDZ_
├── ls2
├── passwd.txt
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-chronyd.service-mKqSc7
│    └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vgauthd.service-OgNGdX
│    └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vmtoolsd.service-NlfJGP
│    └── tmp
│        └── vmware-root
└── yum.log

11 directories, 6 files
[root@evan-01 tmp]# 

然后把刚才复制的evan整个目录和里面的文件删除

[root@evan-01 tmp]# rm evan/one/test.txt 
rm:是否删除普通空文件 "evan/one/test.txt"?y
[root@evan-01 tmp]# rmdir evan/one/
[root@evan-01 tmp]# rmdir evan/
[root@evan-01 tmp]# tree /tmp            
/tmp
├── evanlinux
│    └── one
│        └── test.txt
├── ks-script-R9kDZ_
├── ls2
├── passwd.txt
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-chronyd.service-mKqSc7
│   └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vgauthd.service-OgNGdX
│   └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vmtoolsd.service-NlfJGP
│   └── tmp
│        └── vmware-root
└── yum.log

9 directories, 5 files
[root@evan-01 tmp]#

!$ 执行上一条命令的最后一个参数

[root@evan-01 tmp]# tree /tmp
/tmp
├── evanlinux
│   └── one
│       └── test.txt
├── ks-script-R9kDZ_
├── ls2
├── passwd.txt
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-chronyd.service-mKqSc7
│   └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vgauthd.service-OgNGdX
│  └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vmtoolsd.service-NlfJGP
│   └── tmp
│       └── vmware-root
└── yum.log

9 directories, 5 files
[root@evan-01 tmp]# cp -r evanlinux/ evan/
[root@evan-01 tmp]# tree !$
tree evan/
evan/
└── one
    └── test.txt

1 directory, 1 file
[root@evan-01 tmp]# 

cp -i 表示什么意思?
安全选项,和rm 类似,如果遇到一个存在的文件,会问是否覆盖

[root@evan-01 tmp]# which cp
alias cp='cp -i'
        /usr/bin/cp
[root@evan-01 tmp]# which rm
alias rm='rm -i'
        /usr/bin/rm
[root@evan-01 tmp]# cp /etc/passwd /tmp/passwd.txt 
cp:是否覆盖"/tmp/passwd.txt"? ^C
[root@evan-01 tmp]# 

如果不想让它提示的话,直接这么写

[root@evan-01 tmp]# /usr/bin/cp /etc/passwd /tmp/passwd.txt 
[root@evan-01 tmp]#

复制目录到另一个目录,看会不会被覆盖
复制目录到另一个目录,如果目录存在,就在复制一份到这个目录里面

[root@evan-01 tmp]# tree /tmp
/tmp
├── evan
│  └── one
│      └── test.txt
├── evanlinux
│   └── one
│       └── test.txt
├── ks-script-R9kDZ_
├── ls2
├── passwd.txt
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-chronyd.service-mKqSc7
│   └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vgauthd.service-OgNGdX
│   └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vmtoolsd.service-NlfJGP
│   └── tmp
│       └── vmware-root
└── yum.log

11 directories, 6 files
[root@evan-01 tmp]# cp -r evanlinux/ evan/
[root@evan-01 tmp]# tree !$
tree evan/
evan/
├── evanlinux
│   └── one
│       └── test.txt
└── one
    └── test.txt

3 directories, 2 files
[root@evan-01 tmp]#

复制目录到另一个目录,如果目录不存在会复制一份并且把名字改了

[root@evan-01 tmp]# tree
.
├── evan
│   ├── evanlinux
│   │   └── one
│   │       └── test.txt
│   └── one
│      └── test.txt
├── evanlinux
│   └── one
│       └── test.txt
├── ks-script-R9kDZ_
├── ls2
├── passwd.txt
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-chronyd.service-mKqSc7
│   └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vgauthd.service-OgNGdX
│   └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vmtoolsd.service-NlfJGP
│   └── tmp
│      └── vmware-root
└── yum.log

13 directories, 7 files
[root@evan-01 tmp]# cp -r evanlinux/ evanlinux2/
[root@evan-01 tmp]# tree
.
├── evan
│   ├── evanlinux
│   │   └── one
│   │       └── test.txt
│   └── one
│      └── test.txt
├── evanlinux
│   └── one
│       └── test.txt
├── evanlinux2
│   └── one
│       └── test.txt
├── ks-script-R9kDZ_
├── ls2
├── passwd.txt
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-chronyd.service-mKqSc7
│   └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vgauthd.service-OgNGdX
│   └── tmp
├── systemd-private-7125f715cce542ff8ebf692caabfdafa-vmtoolsd.service-NlfJGP
│   └── tmp
│       └── vmware-root
└── yum.log

15 directories, 8 files
[root@evan-01 tmp]#
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值