cp - copy files and directories 复制文件和目录
-
语法:和mv类似
cp [OPTION]… [-T] SOURCE DEST
cp [OPTION]… SOURCE… DIRECTORY
cp [OPTION]… -t DIRECTORY SOURCE… -
DESCRIPTION Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.复制一个源文件或多个到目标目录
-
-a, --archive 保存所有属性,复制目录
-
–attributes-only 只复制属性 时间戳没有拷贝
cp --attributes-only test.txt tes.txt
-rw-r--r--. 2 root root 19 7月 9 11:32 test.txt
-rw-r--r--. 1 root root 0 7月 10 11:09 tes.txt
[root@myhost ~]# cp test.txt test.txt
cp: "test.txt" 与"test.txt" 为同一文件
- –backup[=CONTROL] 给覆盖的文件一个拷贝
- -b 拷贝覆盖的文件
- -f, --force 如目标文件不能被打开,移除之然后拷贝
- -i 覆盖之前提示
[root@myhost ~]# cp -f test.txt test
cp:是否覆盖"test"?
- -l, --link 不拷贝只是创建硬链接
- -n, 不要覆盖已存在的wenj
- -p 保存权限,拥有关系和时间戳
- -R, -r, --recursive 迭代递归目录
[root@myhost ~]# cp mvdes mvdes~~~
cp: 略过目录"mvdes"
- -s, --symbolic-link 制作软连接
- -u, --update 只有当源文件比目标文件更新时,才会拷贝文件