1、命令格式:

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

2、命令功能:

  将源文件复制至目标文件,或将多个源文件复制至目标目录。

3、命令参数:

-a:此参数的效果和同时指定"-dpR"参数相同;
-d:当复制符号连接时,把目标文件或目录也建立为符号连接,并指向与源文件或目录连接的原始文件或目录;
-f:强行复制文件或目录,不论目标文件或目录是否已存在;
-i:覆盖既有文件之前先询问用户;
-l:对源文件建立硬连接,而非复制文件;
-p:保留源文件或目录的属性;
-R/r:递归处理,将指定目录下的所有文件与子目录一并处理;
-s:对源文件建立符号连接,而非复制文件;
-u:使用这项参数后只会在源文件的更改时间较目标文件更新时或是名称相互对应的目标文件并不存在时,才复制文件;
-S:在备份文件时,用指定的后缀“SUFFIX”代替文件的默认后缀;
-b:覆盖已存在的文件目标前将目标文件备份;
-v:详细显示命令执行的操作。

4、简单实例:

(1)、复制单个文件到目标目录,文件在目标文件中不存在

命令:

cp a.txt test1/
输出:

felix@felix-computer:~/test$ tree
.
├── a.txt
└── test1 1 directory, 1 file
felix@felix-computer:~/test$ cp a.txt test1/
felix@felix-computer:~/test$ tree
.
├── a.txt
└── test1
└── a.txt 1 directory, 2 files

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

命令:

  cp -i a.txt test1/
输出:

felix@felix-computer:~/test$ tree
.
├── a.txt
└── test1
└── a.txt 1 directory, 2 files
felix@felix-computer:~/test$ cp -i a.txt test1/
cp:是否覆盖'test1/a.txt'? y
felix@felix-computer:~/test$ tree
.
├── a.txt
└── test1
└── a.txt 1 directory, 2 files

(3)、复制整个目录

命令:

  cp -r test1 test2

输出:

当文件夹存在时,赋值到目标文件夹中
felix@felix-computer:~/test$ tree
.
├── test1
│   └── a.txt
└── test2 2 directories, 1 file
felix@felix-computer:~/test$ cp -r test1 test2
felix@felix-computer:~/test$ tree
.
├── test1
│   └── a.txt
└── test2
└── test1
└── a.txt 3 directories, 2 files
当文件夹不存在时,新建
felix@felix-computer:~/test$ tree
.
├── test1
│   └── a.txt
└── test2
└── test1
└── a.txt 3 directories, 2 files
felix@felix-computer:~/test$ cp -r test1 test3
felix@felix-computer:~/test$ tree
.
├── test1
│   └── a.txt
├── test2
│   └── test1
│   └── a.txt
└── test3
└── a.txt 4 directories, 3 files

(4)、给文件创建一个快捷方式

命令:

  cp -s test1/test2/test3/a.txt a_link.txt

输出:

felix@felix-computer:~/test$ tree
.
└── test1
└── test2
└── test3
└── a.txt 3 directories, 1 file
felix@felix-computer:~/test$ cp -s test1/test2/test3/a.txt a_link.txt
felix@felix-computer:~/test$ tree
.
├── a_link.txt -> test1/test2/test3/a.txt
└── test1
└── test2
└── test3
└── a.txt 3 directories, 2 files

最新文章

  1. linux下共享库的注意点之-fpic
  2. C# 模拟按下回车键自动登录
  3. java 时间转换
  4. fwrite错误
  5. MVC4 Forms 验证,部署到Hyper-v上.FormsAuthentication.SetAuthCookie无效的问题
  6. jquery插件——图片放大器
  7. 火星A+B(字符串整形转化,进制)
  8. 如何自动增加和从代码读取Xcode项目的版本号
  9. flex 圣杯布局
  10. [Swift]LeetCode900. RLE 迭代器 | RLE Iterator
  11. python-文件读写
  12. C# 父子页面传值
  13. 分形之科赫(Koch)雪花
  14. 关于获取Windows下性能参数的总结
  15. cat /proc/net/sockstat
  16. Shell中的表达式及IF
  17. 【转】每天一个linux命令目录
  18. sqoop2的安装配置
  19. 由于C++类库版本不同导致的OpenCV编译链接错误
  20. .net+jquery+ashx实现客户端模拟登陆扩展

热门文章

  1. Scratch(二)来不及解释了,马上开始编程游戏
  2. C#-System.Dynamic.ExpandoObject
  3. cdc跨时钟域处理-结绳握手法
  4. linux管道和重定向
  5. nginx 作为静态资源web服务
  6. 利用 pandas库读取excel表格数据
  7. Linux命令——ps、pstree
  8. 【kernel】Centos 云上升级内核失败 如何处理【笔记记录转】
  9. cuda实现向量相加
  10. (2) openstack--keystone