cp 复制,拷贝
选项:
-r #递归复制 复制目录时所使用的
-p #保持源文件属性
-d #复制的时候保持软连接
-a === -pdr
-t #把源文件的位置根目标目录的位置进行调换 在批量拷贝文件时使用
-i #当拷贝的文件在目标目录已经存在时,提示是否覆盖 系统自带的别名
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
[root@clf ~]# cp /etc/hosts /root [root@clf ~]# cp /etc/passwd ./ [root@clf ~]# cp /etc/resolv.conf . [root@clf ~]# ll total 12 -rw-r--r--. 1 root root 158 Jul 9 09:11 hosts -rw-r--r--. 1 root root 873 Jul 9 09:11 passwd -rw-r--r--. 1 root root 51 Jul 9 09:11 resolv.conf [root@clf ~]# cp /opt/ ./ cp: omitting directory ‘/opt/’ [root@clf ~]# cp -r /opt/ ./ [root@clf ~]# ll total 12 -rw-r--r--. 1 root root 158 Jul 9 09:11 hosts drwxr-xr-x. 2 root root 6 Jul 9 09:14 opt -rw-r--r--. 1 root root 873 Jul 9 09:11 passwd -rw-r--r--. 1 root root 51 Jul 9 09:11 resolv.conf [root@clf ~]# ll /etc/grub2.cfg lrwxrwxrwx. 1 root root 22 Jul 6 02:14 /etc/grub2.cfg -> ../boot/grub2/grub.cfg [root@clf ~]# cp /etc/grub2.cfg ./ [root@clf ~]# ll total 20 -rw-r--r--. 1 root root 4229 Jul 9 09:16 grub2.cfg -rw-r--r--. 1 root root 158 Jul 9 09:11 hosts drwxr-xr-x. 2 root root 6 Jul 9 09:14 opt -rw-r--r--. 1 root root 873 Jul 9 09:11 passwd -rw-r--r--. 1 root root 51 Jul 9 09:11 resolv.conf [root@clf ~]# rm -f grub2.cfg [root@clf ~]# cp -d /etc/grub2.cfg ./ [root@clf ~]# ll total 12 lrwxrwxrwx. 1 root root 22 Jul 9 09:16 grub2.cfg -> ../boot/grub2/grub.cfg -rw-r--r--. 1 root root 158 Jul 9 09:11 hosts drwxr-xr-x. 2 root root 6 Jul 9 09:14 opt -rw-r--r--. 1 root root 873 Jul 9 09:11 passwd -rw-r--r--. 1 root root 51 Jul 9 09:11 resolv.conf [root@clf ~]# cp -t ./ /etc/fstab [root@clf ~]# ll total 16 lrwxrwxrwx. 1 root root 7 Jul 6 02:13 bin -> usr/bin -rw-r--r--. 1 root root 501 Jul 9 09:21 fstab lrwxrwxrwx. 1 root root 22 Jul 9 09:16 grub2.cfg -> ../boot/grub2/grub.cfg -rw-r--r--. 1 root root 158 Jul 9 09:11 hosts drwxr-xr-x. 2 root root 6 Jul 9 09:14 opt -rw-r--r--. 1 root root 873 Jul 9 09:11 passwd -rw-r--r--. 1 root root 51 Jul 9 09:11 resolv.conf [root@clf ~]# cp /etc/hosts ./ cp: overwrite ‘./hosts’? n [root@clf ~]# alias alias cp='cp -i' #强制覆盖不提示 临时取消别名 [root@clf ~]# \cp /etc/hosts ./ |