首页 > 系统相关 >【Linux】cp -r 命令实验

【Linux】cp -r 命令实验

时间:2024-10-24 22:17:12浏览次数:3  
标签:txt container appx sxnhtc test2 实验 Linux cp

1.命令说明 

命令:cp -r  source  dest

说明:该命令复制source  到 dest。可以单个文件复制,也可以带目录层级复制。

          source 是具体文件时,dest如果是目录,即带/ 的,则文件生成在dest目录中。如果dest是不带/的,文件换名为dest文件,内容复制过去。

          source 是具体目录时,dest如果是目录,即带/ 的,则生成在dest目录中,按层级的source下目录及文件。

总结:即源是文件,目标 指定文件则替换,未指定文件 则新建文件。

              源是路径,将在目标 中生成 源路径下的 所有目录及文件。

说明:

       -r:既复制当前目录下的文件,也复制当前目录下的文件夹。

  -R:只复制当前目录下的文件,不复制当前目录下的文件夹

 2.实验

源文件:/home/sxnhtc/script/performance/test/test1/test2  有1.txt  2.txt

2.1 源是文件,目标 指定文件则替换,未指定文件 则新建文件

cp -r  ./test/test1/test2/1.txt   目标

      目标如果是路径,即带/,必须存在该路径。会复制到目标路径下 1.txt。

      目标如果 不带/,默认是文件,不存在则创建,存在则覆盖。

cp -r  ./test/test1/test2/1.txt ./ttotest    

[sxnhtc@appx-container performance]$ cp -r  ./test/test1/test2/1.txt ./ttotest
[sxnhtc@appx-container performance]$ cd ttotest
-bash: cd: ttotest: 不是目录
[sxnhtc@appx-container performance]$ cat ttotest
hello

[sxnhtc@appx-container performance]$ 
cp -r  ./test/test1/test2/1.txt ./ttotest/

[sxnhtc@appx-container performance]$ cp -r  ./test/test1/test2/1.txt ./ttotest/
cp: failed to access "./ttotest/": 不是目录
[sxnhtc@appx-container performance]$
#ttotest1 目录不存在
cp -r  ./test/test1/test2/1.txt ./ttotest1/  

[sxnhtc@appx-container performance]$ cp -r  ./test/test1/test2/1.txt ./ttotest1/
cp: 无法创建普通文件"./ttotest1/": 不是目录
[sxnhtc@appx-container performance]$
#目录 totest2、totest3 已存在时,该层目录下复制文件
cp -r ./test/test1/test2/1.txt ./totest2
cp -r ./test/test1/test2/1.txt ./totest3/

[sxnhtc@appx-container performance]$ cp -r ./test/test1/test2/1.txt ./totest2
[sxnhtc@appx-container performance]$ ll totest2
总用量 4
-rw-rw-r-- 1 sxnhtc sxnhtc  7 10月 19 12:00 1.txt
drwxrwxr-x 3 sxnhtc sxnhtc 27 10月 19 11:51 test1
[sxnhtc@appx-container performance]$ cp -r ./test/test1/test2/1.txt ./totest3/
[sxnhtc@appx-container performance]$ ll totest3
总用量 4
-rw-rw-r-- 1 sxnhtc sxnhtc  7 10月 19 12:00 1.txt
drwxrwxr-x 3 sxnhtc sxnhtc 27 10月 19 11:48 test1
[sxnhtc@appx-container performance]$

 

2.2 源是路径,将在目标 中生成 源路径下的 所有目录及文件

cp -r ./test ./totest1   或  cp -r ./test/ ./totest2   或 cp -r ./test/ ./totest3/

         #把test文件夹替换为 totest1/2/3文件夹,子目录不变,全部复制。totest1自动创建。

         结果:从     ./test/test1/test2  有1.txt  2.txt

                   到 ./totest1/test1/test2  有1.txt  2.txt

因此,如果前后都是目录的话,源和目标的层级是一样的。

cp -r ./test ./totest1

[sxnhtc@appx-container performance]$ cp -r ./test ./totest1
[sxnhtc@appx-container performance]$ cd totest1
[sxnhtc@appx-container totest1]$ ll
总用量 0
drwxrwxr-x 3 sxnhtc sxnhtc 27 10月 19 11:34 test1
[sxnhtc@appx-container totest1]$ cd test1/test2
[sxnhtc@appx-container test2]$ ll
总用量 8
-rw-rw-r-- 1 sxnhtc sxnhtc 7 10月 19 11:34 1.txt
-rw-rw-r-- 1 sxnhtc sxnhtc 7 10月 19 11:34 2.txt
[sxnhtc@appx-container test2]$ pwd
/home/sxnhtc/script/performance/totest1/test1/test2
[sxnhtc@appx-container test2]$
cp -r ./test/ ./totest3/

[sxnhtc@appx-container performance]$ cp -r ./test/ ./totest3/
[sxnhtc@appx-container performance]$ cd /home/sxnhtc/script/performance/totest3/test1/test2/
[sxnhtc@appx-container test2]$ ll
总用量 8
-rw-rw-r-- 1 sxnhtc sxnhtc 7 10月 19 11:48 1.txt
-rw-rw-r-- 1 sxnhtc sxnhtc 7 10月 19 11:48 2.txt
[sxnhtc@appx-container test2]$
cp -r ./test/ ./totest2

[sxnhtc@appx-container performance]$ cp -r ./test/ ./totest2
[sxnhtc@appx-container performance]$ cd totest2/test1/test2
[sxnhtc@appx-container test2]$ ll
总用量 8
-rw-rw-r-- 1 sxnhtc sxnhtc 7 10月 19 11:51 1.txt
-rw-rw-r-- 1 sxnhtc sxnhtc 7 10月 19 11:51 2.txt
[sxnhtc@appx-container test2]$

总结:其实cp指定文件时,-r 不用写,也可以创建。

          -r 或-R只针对 源是目录时,是否拷贝带层级或直接文件。

cp   ./test/test1/test2/2.txt ./totest2/

[sxnhtc@appx-container performance]$ cp   ./test/test1/test2/2.txt ./totest2/
[sxnhtc@appx-container performance]$ ll totest2
总用量 8
-rw-rw-r-- 1 sxnhtc sxnhtc  7 10月 19 12:00 1.txt
-rw-rw-r-- 1 sxnhtc sxnhtc  7 10月 19 12:24 2.txt
drwxrwxr-x 3 sxnhtc sxnhtc 27 10月 19 11:51 test1
[sxnhtc@appx-container performance]$
#totestbb 不存在,-R将具体文件 直接复制到totestbb文件中,没有层级
cp -R  ./test/test1/test2/  ./totestbb/

[sxnhtc@appx-container performance]$  cp -R  ./test/test1/test2/  ./totestbb/
[sxnhtc@appx-container performance]$ ll totestbb
总用量 8
-rw-rw-r-- 1 sxnhtc sxnhtc 7 10月 19 12:35 1.txt
-rw-rw-r-- 1 sxnhtc sxnhtc 7 10月 19 12:35 2.txt
[sxnhtc@appx-container performance]$
#totestcc不存在,会将test1/test2目录及文件,复制到totestcc中
cp -R  ./test/  ./totestcc/

[sxnhtc@appx-container performance]$  cp -R  ./test/  ./totestcc/
[sxnhtc@appx-container performance]$ cd totestcc
[sxnhtc@appx-container totestcc]$ ll
总用量 0
drwxrwxr-x 3 sxnhtc sxnhtc 27 10月 19 12:40 test1
[sxnhtc@appx-container totestcc]$ cd test1/test2
[sxnhtc@appx-container test2]$ ll
总用量 8
-rw-rw-r-- 1 sxnhtc sxnhtc 7 10月 19 12:40 1.txt
-rw-rw-r-- 1 sxnhtc sxnhtc 7 10月 19 12:40 2.txt
[sxnhtc@appx-container test2]$

 


 Oracle其他文档,希望互相学习,共同进步

Oracle-找回误删的表数据(LogMiner 挖掘日志)_oracle日志挖掘恢复数据-CSDN博客

oracle 跟踪文件--审计日志_oracle审计日志-CSDN博客

ORA-12899报错,遇到数据表某字段长度奇怪现象:“Oracle字符型,长度50”但length查却没有50_varchar(50) oracle 超出截断-CSDN博客

EXP-00091: Exporting questionable statistics.解决方案-CSDN博客


 项目管理--相关知识   

项目管理-项目绩效域1/2-CSDN博客

项目管理-项目绩效域1/2_八大绩效域和十大管理有什么联系-CSDN博客

项目管理-项目绩效域2/2_绩效域 团不策划-CSDN博客

高项-案例分析万能答案(作业分享)-CSDN博客

项目管理-计算题公式【复习】_项目管理进度计算题公式:乐观-CSDN博客

项目管理-配置管理与变更-CSDN博客

项目管理-项目管理科学基础-CSDN博客

项目管理-高级项目管理-CSDN博客

标签:txt,container,appx,sxnhtc,test2,实验,Linux,cp
From: https://blog.csdn.net/weixin_42081167/article/details/143136096

相关文章

  • [项目][boost搜索引擎#4] cpp-httplib使用 | log.hpp | 前端 | 测试及总结
    目录编写http_server模块1.引入cpp-httplib到项目中2.cpp-httplib的使用介绍3.正式编写http_server九、添加日志到项目中十、编写前端模块十一.详解传gitee十二、项目总结项目的扩展写在前面项目gitee已经上传啦(还是决定将学校和个人的gitee区分开来,所以......
  • linux目录和文件命令
    目录命令ls功能:显示目录的列表用法ls[参数][对象]-a:显示所有文件,包括隐藏文件-l:显示文件详细信息-t:按照时间顺序排序-r:逆向排序pwd功能:显示当前目录的绝对路径用法:pwdcd功能:切换操作目录用法:cd[对象].当前目录..上一层目录上一次所在目录~home目......
  • 实验三
    任务1:1#include<stdio.h>23charscore_to_grade(intscore);45intmain(){6intscore;7chargrade;89while(scanf("%d",&score)!=EOF){10grade=score_to_grade(score);11printf(&quo......
  • CPP vector动态数组的基本用法
    #include<iostream>#include<vector>#include<algorithm>usingnamespacestd;intmain()#defineintlonglong//不能放在主函数之前,因为主函数的返回类型必须是int{ vector<int>v={0,0,0,0}; v.push_back(1); v.push_back(2); v.push_back(2); v.push_back(3......
  • 【保姆级IDF】ESP32使用WIFI作为AP模式TCP通信:连接客户端+一对多通信
    #1024程序员节|征文#Tips:抛砖引玉,本文记录ESP32学习过程中遇到的收获。如有不对的地方,欢迎指正。1.前言    关于ESP32的WIFI这部分基础知识,在网上可以找到许多,包括TCP协议、套接字等等,博主之前的文章也有介绍,在此本文不再赘述,直接讲清楚标题功能如何实现,并说明......
  • mac scrcpy 报错 does not exist or is not a regular file,ERROR: Server connection
    scrcpymac与极空间冲突问题:➜~scrcpyscrcpy2.7<https://github.com/Genymobile/scrcpy>INFO:ADBdevicefound:INFO:-->(usb)8AJY0LU0QdevicePixel_3_XLstat:NosuchfileordirectoryERROR:'/Applications/极空间.ap......
  • 实验二
    实验一代码:1#include"t.h"2#include<iostream>34usingstd::cout;5usingstd::endl;67voidtest();89intmain(){10test();11cout<<"\nmain:\n";12cout<<"Tob......
  • Linux常用命令
    1、cd-切换当前目录这是一个最基本,也是最常用的命令,它用于切换当前目录,它的参数是要切换到的目录的路径,可以是绝对路径,也可以是相对路径。cd/root #切换到目录/rootcd./path #切换到当前目录下的path目录中,“.”表示当前目录cd../path #切换到上层目录中的path目录中,“..”......
  • 20222403 2024-2025-1 《网络与系统攻防技术》实验三实验报告
    1.实验内容1.1.实践内容(1)正确使用msf编码器,veil-evasion,自己利用shellcode编程等免杀工具或技巧正确使用msf编码器,使用msfvenom生成如jar之类的其他文件veil,加壳工具使用C+shellcode编程(2)通过组合应用各种技术实现恶意代码免杀如果成功实现了免杀的,简单语言描述原......
  • [Go] 如何妥善处理 TCP 代理中连接的关闭
    如何妥善处理TCP代理中连接的关闭相比较于直接关闭TCP连接,只关闭TCP连接读写使用单工连接的场景较少,但通用的TCP代理也需要考虑这部分场景。背景今天在看老代码的时候,发现一个TCP代理的核心函数实现的比较粗糙,收到EOF后直接粗暴关闭两条TCP连接。funcConnCat(u......