cp 复制 copy
复制文件 -v显示过程
[root@rstx-53 test]# touch file.txt
[root@rstx-53 test]# cp file.txt /tmp/file_copy
[root@rstx-53 test]# ll /tmp/file_copy
-rw-r--r-- 1 root root 0 Feb 26 13:19 /tmp/file_copy
[root@rstx-53 test]# cp file.txt /tmp/file_copy1 -v
‘file.txt’ -> ‘/tmp/file_copy1’
复制过程中不改变属主属组
[root@rstx-53 test]# ll
-rw-r--r-- 1 root root 0 Feb 26 13:19 file.txt
[root@rstx-53 test]# chown yangtao.yangtao file.txt
[root@rstx-53 test]# ll
-rw-r--r-- 1 yangtao yangtao 0 Feb 26 13:19 file.txt
[root@rstx-53 test]# cp file.txt /tmp/file.txt
[root@rstx-53 test]# ll /tmp/file.txt
-rw-r--r-- 1 root root 0 Feb 26 13:23 /tmp/file.txt
[root@rstx-53 test]# ll /tmp/file.txt
-rw-r--r-- 1 root root 0 Feb 26 13:23 /tmp/file.txt
[root@rstx-53 test]# cp file.txt /tmp/file.txt -p
cp: overwrite ‘/tmp/file.txt’? y
[root@rstx-53 test]# ll /tmp/file.txt
-rw-r--r-- 1 yangtao yangtao 0 Feb 26 13:19 /tmp/file.txt
复制目录 -r 递归复制目录
[root@rstx-53 test]# cp /etc/ /tmp/
cp: omitting directory ‘/etc/’
[root@rstx-53 test]# cp /etc/ /tmp/ -r
[root@rstx-53 test]# ll /tmp/etc/
跳出交互式复制目录文件 alias cp -i
[root@rstx-53 test]# cp /etc/ /tmp/ -rf
cp: overwrite ‘/tmp/etc/fstab’? ^C
[root@rstx-53 test]# ^C
[root@rstx-53 test]# cp /etc/ /tmp/ -r
cp 备份文件
[root@rstx-53 test]# cp -v /etc/{hosts,hosts.bak}
‘/etc/hosts’ -> ‘/etc/hosts.bak’
[root@rstx-53 test]# cp -v /etc/hosts{,-bak}
‘/etc/hosts’ -> ‘/etc/hosts-bak’
反转 -t
[root@rstx-53 test]# cp -vt /tmp/ /etc/hosts
‘/etc/hosts’ -> ‘/tmp/hosts’