菜鸟笔记
提升您的技术认知

linux系统如何将一个文件同时复制多份-ag真人游戏

 1、创建测试数据 a.txt

[root@linuxprobe test]# seq 10 > a.txt [root@linuxprobe test]# ls a.txt [root@linuxprobe test]# cat a.txt 1
2
3
4
5
6
7
8
9
10

 

 2、利用tee命令将文件同时复制多份  ## 只适用于小文件,因为cat命令要打开文件

[root@linuxprobe test]# cat a.txt | tee dup{1..10}.txt ## 利用tee命令将a.txt复制十份 1
2
3
4
5
6
7
8
9
10 [root@linuxprobe test]# ls a.txt dup10.txt dup1.txt dup2.txt dup3.txt dup4.txt dup5.txt dup6.txt dup7.txt dup8.txt dup9.txt [root@linuxprobe test]# md5sum *.txt ## 检测复制结果 3b0332e02daabf31651a5a0d81ba830a a.txt 3b0332e02daabf31651a5a0d81ba830a dup10.txt 3b0332e02daabf31651a5a0d81ba830a dup1.txt 3b0332e02daabf31651a5a0d81ba830a dup2.txt 3b0332e02daabf31651a5a0d81ba830a dup3.txt 3b0332e02daabf31651a5a0d81ba830a dup4.txt 3b0332e02daabf31651a5a0d81ba830a dup5.txt 3b0332e02daabf31651a5a0d81ba830a dup6.txt 3b0332e02daabf31651a5a0d81ba830a dup7.txt 3b0332e02daabf31651a5a0d81ba830a dup8.txt 3b0332e02daabf31651a5a0d81ba830a dup9.txt

 

3、利用for循环将文件复制多份,适用于大小文件

[root@linuxprobe test]# rm dup*  ## 删除上一步测试结果 [root@linuxprobe test]# ls a.txt [root@linuxprobe test]# for i in `seq 10`;do cp a.txt cp$i.txt;done ## 利用for循环,将a.txt复制10份 [root@linuxprobe test]# ls a.txt cp10.txt cp1.txt cp2.txt cp3.txt cp4.txt cp5.txt cp6.txt cp7.txt cp8.txt cp9.txt [root@linuxprobe test]# md5sum *  ## 检测复制结果 3b0332e02daabf31651a5a0d81ba830a a.txt 3b0332e02daabf31651a5a0d81ba830a cp10.txt 3b0332e02daabf31651a5a0d81ba830a cp1.txt 3b0332e02daabf31651a5a0d81ba830a cp2.txt 3b0332e02daabf31651a5a0d81ba830a cp3.txt 3b0332e02daabf31651a5a0d81ba830a cp4.txt 3b0332e02daabf31651a5a0d81ba830a cp5.txt 3b0332e02daabf31651a5a0d81ba830a cp6.txt 3b0332e02daabf31651a5a0d81ba830a cp7.txt 3b0332e02daabf31651a5a0d81ba830a cp8.txt 3b0332e02daabf31651a5a0d81ba830a cp9.txt

 

4、利用echo 、xargs 命令将文件复制多份   

[root@linuxprobe test]# rm cp*  ## 删除上一步测试文件 [root@linuxprobe test]# ls a.txt [root@linuxprobe test]# echo "cp1.txt cp2.txt cp3.txt cp4.txt" | xargs -n 1 cp a.txt ## 利用echo 、xargs 复制文件多份 [root@linuxprobe test]# ls a.txt cp1.txt cp2.txt cp3.txt cp4.txt [root@linuxprobe test]# md5sum *  ## 检测复制结果 3b0332e02daabf31651a5a0d81ba830a a.txt 3b0332e02daabf31651a5a0d81ba830a cp1.txt 3b0332e02daabf31651a5a0d81ba830a cp2.txt 3b0332e02daabf31651a5a0d81ba830a cp3.txt 3b0332e02daabf31651a5a0d81ba830a cp4.txt

 

网站地图