当前位置:网站首页>如何把大的‘tar‘存档文件分割成特定大小的多个文件
如何把大的‘tar‘存档文件分割成特定大小的多个文件
2022-07-05 13:38:00 【yuyuyuliang00】
你担心通过网络传输或者上传大型文件吗? 现在不用再担心了,因为你可以通过分割你的文件为指定大小块,以比特移动你的文件来处理缓慢的网速。
我们在这里应该简要地利用存档文件地创建斌且分割它们为一个所选大小块。我们使用tar,在Linux上最流行的存档工具之一并使用split工具帮助我们分割存档文件成小块。
在我们进一步前,我们注意如何使用这些工具,tar和split命令的一般语法如下:
# tar options archive-name files
# split options file "prefix”
我们研究一些示例来演示主要概念。
示例1:我们可以按如下创建一个存档文件:
[[email protected] ~]# tar -cvjf test.tar.br2 test/*
test/fold/
test/guid.txt
test/perm.txt
test/rock.html
test/Rock.txt
test/Rocky/
test/Rocky/1.txt
test/Rocky/2.txt
test/Rocky/3.txt
test/Rocky/4.txt
test/Rocky/5.txt
test/rocky.c
test/rocky.sh
test/suid.txt
test/test.tar.gz
[[email protected] ~]# ls
test test.tar.br2
要确认这个存档文件已经被创建并且也检查它的大小,我们可以使用ls命令:
[[email protected] ~]# ls -lh test.tar.br2
-rw-r--r-- 1 root root 2.9M Jul 3 22:21 test.tar.br2
接着使用split工具,我们按以下把test.tar.br2存档文件分割为每个尺寸1M的小块:
[[email protected] ~]# split -b 1M test.tar.br2 "test.tar.br2.part"
[[email protected] ~]# ls -lh
total 5.8M
drwxr-xr-x 4 root root 177 Jul 3 09:04 test
-rw-r--r-- 1 root root 2.9M Jul 3 22:21 test.tar.br2
-rw-r--r-- 1 root root 1.0M Jul 3 22:26 test.tar.br2.partaa
-rw-r--r-- 1 root root 1.0M Jul 3 22:26 test.tar.br2.partab
-rw-r--r-- 1 root root 917K Jul 3 22:26 test.tar.br2.partac
如你从以上命令输出所见,tar存档文件已经被分成了3个部分。
注意:在以上split命令中,选项-b用于指定每个块的尺寸,而"test.tar.br2.part"是分割后创建的每个块文件名称的前缀。
示例2:在这个实例中,我们按如下使用管道连接tar的输出到split:
[[email protected] ~]# tar -cvzf - test/* | split -b 500K - "test_2.tar.gz.part"
test/fold/
test/guid.txt
test/perm.txt
test/rock.html
test/Rock.txt
test/Rocky/
test/Rocky/1.txt
test/Rocky/2.txt
test/Rocky/3.txt
test/Rocky/4.txt
test/Rocky/5.txt
test/rocky.c
test/rocky.sh
test/suid.txt
test/test.tar.gz
确认这些文件:
[[email protected] ~]# ls -lh test_2.tar.gz.part*
-rw-r--r-- 1 root root 500K Jul 3 23:41 test_2.tar.gz.partaa
-rw-r--r-- 1 root root 500K Jul 3 23:41 test_2.tar.gz.partab
-rw-r--r-- 1 root root 500K Jul 3 23:41 test_2.tar.gz.partac
-rw-r--r-- 1 root root 500K Jul 3 23:41 test_2.tar.gz.partad
-rw-r--r-- 1 root root 500K Jul 3 23:41 test_2.tar.gz.partae
-rw-r--r-- 1 root root 449K Jul 3 23:41 test_2.tar.gz.partaf
在这个示例中,如你注意到我们不需要指定一个存档名称,只要使用'-'符号。
在分割后如何组合tar文件
在Linux中成功分割tar文件或者任何大型文件后,你可以使用cat命令组合这些文件。使用cat是执行组合操作的最高效和可靠方法。
要组合回所有块或tar文件,我们发出以下命令:
[[email protected] back]# ls
test_2.tar.gz.partaa test_2.tar.gz.partac test_2.tar.gz.partae
test_2.tar.gz.partab test_2.tar.gz.partad test_2.tar.gz.partaf
[[email protected] back]# cat test_2.tar.gz.part* > backup.tar.gz
[[email protected] back]# ls
backup.tar.gz test_2.tar.gz.partab test_2.tar.gz.partad test_2.tar.gz.partaf
test_2.tar.gz.partaa test_2.tar.gz.partac test_2.tar.gz.partae
我们能够看到在运行cat命令后,它组合我们先前创建的所有小块成相同大小的原先tar存档文件。
解压组合回的文件,检查其中内容:
[[email protected] back]# tar -xvzf backup.tar.gz
test/fold/
test/guid.txt
test/perm.txt
test/rock.html
test/Rock.txt
test/Rocky/
test/Rocky/1.txt
test/Rocky/2.txt
test/Rocky/3.txt
test/Rocky/4.txt
test/Rocky/5.txt
test/rocky.c
test/rocky.sh
test/suid.txt
test/test.tar.gz
边栏推荐
- [notes of in-depth study paper]transbtsv2: wider instead of deep transformer for medical image segmentation
- 53. Maximum subarray sum: give you an integer array num, please find a continuous subarray with the maximum sum (the subarray contains at least one element) and return its maximum sum.
- 49. 字母异位词分组:给你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。 字母异位词 是由重新排列源单词的字母得到的一个新单词,所有源单词中的字母通常恰好只用一次。
- Solve the problem of "unable to open source file" xx.h "in the custom header file on vs from the source
- 今年上半年,通信行业发生了哪些事?
- Shuttle INKWELL & ink components
- 内网穿透工具 netapp
- 记录一下在深度学习-一些bug处理
- Talk about seven ways to realize asynchronous programming
- French scholars: the explicability of counter attack under optimal transmission theory
猜你喜欢
龙芯派2代烧写PMON和重装系统
What happened to the communication industry in the first half of this year?
C# 对象存储
Flutter draws animation effects of wave movement, curves and line graphs
"Baidu Cup" CTF competition in September, web:upload
The development of speech recognition app with uni app is simple and fast.
jasypt配置文件加密|快速入门|实战
这18个网站能让你的页面背景炫酷起来
ELFK部署
redis6主从复制及集群
随机推荐
53. 最大子数组和:给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
Record in-depth learning - some bug handling
Interviewer soul torture: why does the code specification require SQL statements not to have too many joins?
leetcode 10. Regular expression matching regular expression matching (difficult)
Write API documents first or code first?
How to choose note taking software? Comparison and evaluation of notion, flowus and WOLAI
[notes of in-depth study paper]uctransnet: rethink the jumping connection in u-net from the perspective of transformer channel
restTemplate详解
Difference between avc1 and H264
53. Maximum subarray sum: give you an integer array num, please find a continuous subarray with the maximum sum (the subarray contains at least one element) and return its maximum sum.
Operational research 68 | the latest impact factors in 2022 were officially released. Changes in journals in the field of rapid care
Go array and slice
Redis6 data type and operation summary
Matlab paper chart standard format output (dry goods)
redis6主从复制及集群
Can and can FD
今年上半年,通信行业发生了哪些事?
Laravel framework operation error: no application encryption key has been specified
[daily question] 1200 Minimum absolute difference
Kafaka log collection