21天掌握linux常用命令挑战开启了!今天我们将深入探讨cp命令的用法和功能。
命令简介 cp命令主要用于复制文件或文件夹。你可以将一个或多个源文件或文件夹复制到指定的目标文件或文件夹中,这类似于在Windows系统中复制粘贴文件或文件夹。
英文含义记忆法
cp = copy
语法格式
cp 选项... -T 源文件 目标文件 cp 选项... 源文件... 目录 cp 选项... -t 目录 源文件...
选项说明
注意事项
示例说明
6.1 将一个文件夹及文件夹下所有内容拷贝到另外一个文件夹
[root@iZbp1d8rn0652ia3bzzmioZ local]# cd test1/ [root@iZbp1d8rn0652ia3bzzmioZ test1]# ls -l 总用量 0 -rw-r--r-- 1 root root 0 11月 23 23:00 111111.txt -rw-r--r-- 1 root root 0 11月 23 23:00 1111.txt -rw-r--r-- 1 root root 0 11月 23 22:59 111.txt [root@iZ test1]# cd ../test2/ [root@iZ test2]# ls [root@iZ test2]# cp -r /usr/local/test1/ /usr/local/test2/ [root@iZ test2]# ls test1 [root@iZ test2]# cd test1/ [root@iZ test1]# ls 111111.txt 1111.txt 111.txt [root@iZ test1]#
6.2 将一个文件夹下所有内容拷贝到另外一个文件夹下
drwxr-xr-x 2 root root 55 11月 23 23:00 test1 drwxr-xr-x 2 root root 6 11月 23 23:07 test2 [root@iZ local]# cd test1/ [root@iZ test1]# ls 111111.txt 1111.txt 111.txt [root@iZ test1]# cd ../test2/ [root@iZ test2]# ls [root@iZ test2]# cp /usr/local/test1/* /usr/local/test2 [root@iZ test2]# ls 111111.txt 1111.txt 111.txt [root@iZ test2]#
6.3 目标文件下已经存在复制文件时,在覆盖时会先询问是否执行操作
[root@iZ test2]# ls 111111.txt 1111.txt 111.txt [root@iZ test2]# cd ../test1/ [root@iZ test1]# ls 111111.txt 1111.txt 111.txt [root@iZ test1]# cp -i 111.txt /usr/local/test2 cp:是否覆盖'/usr/local/test2/111.txt'? y [root@iZ test1]#
6.4 原样复制,保留全部
[root@iZ test1]# ls -l 总用量 0 -rw-r--r-- 1 root root 0 11月 23 23:00 111111.txt -rw-r--r-- 1 root root 0 11月 23 23:00 1111.txt -rw-r--r-- 1 root root 0 11月 23 22:59 111.txt [root@iZ test1]# cp 111.txt /usr/local/test2/ [root@iZ test1]# cd /usr/local/test2/ [root@iZ test2]# ls -l 总用量 0 -rw-r--r-- 1 root root 0 11月 23 23:28 111.txt
[root@iZ test1]# ls -l 总用量 0 -rw-r--r-- 1 root root 0 11月 23 23:00 111111.txt -rw-r--r-- 1 root root 0 11月 23 23:00 1111.txt -rw-r--r-- 1 root root 0 11月 23 22:59 111.txt [root@iZ test1]# cp -a 1111.txt /usr/local/test2/ [root@iZ test1]# cd /usr/local/test2/ [root@iZ test2]# ls -l 总用量 0 -rw-r--r-- 1 root root 0 11月 23 23:00 1111.txt -rw-r--r-- 1 root root 0 11月 23 23:28 111.txt
今天的学习内容就到这里了!欢迎大家在评论区参与交流与讨论,一起学习和进步!
系列推荐 日更第1天:Linux常用命令之dnf用法
以上就是日更第2天:Linux常用命令之cp用法的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号