linux中实现将一个文件同时复制到多个目录中
001、echo + xargs + cp实现
[root@pc1 data]# ls ## 测试目录及文件a.txt为测试文件, test01~04为测试目录,均为空目录 a.txt test01 test02 test03 test04 [root@pc1 data]# tree ## 利用tree命令查看文件结构 . ├── a.txt ├── test01 ├── test02 ├── test03 └── test04 4 directories, 1 file [root@pc1 data]# echo ./test01 ./test03 | xargs -n 1 cp -v a.txt ## 使用echo + xargs + cp实现复制到多个目录 ‘a.txt’ -> ‘./test01/a.txt’ ‘a.txt’ -> ‘./test03/a.txt’ [root@pc1 data]# tree ## 利用tree命令查看复制效果 . ├── a.txt ├── test01 │ └── a.txt ├── test02 ├── test03 │ └── a.txt └── test04 4 directories, 3 files
002、利用循环结构实现
[root@pc1 data]# ls a.txt test01 test02 test03 test04 [root@pc1 data]# tree ## 复制前文件结构 . ├── a.txt ├── test01 ├── test02 ├── test03 └── test04 4 directories, 1 file [root@pc1 data]# for i in ./test02 ./test03; do cp a.txt $i; done ## 利用for循环实现复制多个目录 [root@pc1 data]# tree ## 查看复制效果 . ├── a.txt ├── test01 ├── test02 │ └── a.txt ├── test03 │ └── a.txt └── test04 4 directories, 3 files
003、利用数组循环结构
[root@pc1 data]# ls a.txt test01 test02 test03 test04 [root@pc1 data]# tree ## 查看复制前文件结构 . ├── a.txt ├── test01 ├── test02 ├── test03 └── test04 4 directories, 1 file [root@pc1 data]# dirs=("./test01" "./test04") ## 将目的目录保存在数组中 [root@pc1 data]# for i in ${dirs[@]}; do cp a.txt $i; done ## 利用for循环结构实现复制 [root@pc1 data]# tree ## 查看复制效果 . ├── a.txt ├── test01 │ └── a.txt ├── test02 ├── test03 └── test04 └── a.txt 4 directories, 3 files
参考:
001、https://www.yisu.com/zixun/670252.html
002、https://blog.csdn.net/weixin_39704727/article/details/116839392
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2021-10-15 ubuntu 安装 rstudio-server
2020-10-15 plink软件计算snp位点的观测杂合度和期待杂合度