大文件切割技巧

主要用到split命令:可以将一个大文件分割成多个小文件,有时候文件太大了需要将文件分割成更小的片段,如数据库备份sql文件或者应用log

# 分切文件

这里举例分切一个423M的文件,将其分成若干个50m一个的小文件,分出来的文件默认aa,ab,ac..结尾

[root@linux  ]# ll
-rw-r--r-- 1 root root 443222812 Dec 14 09:33 tidb_install.zip
[root@linux  ]# du -sh *
423M	tidb_install.zip
[root@linux  ]# cat tidb_install.zip | split -b 50m - ls_tidb_install.zip 
[root@linux  ]# ll
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipaa
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipab
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipac
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipad
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipae
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipaf
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipag
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipah
-rw-r--r-- 1 root root  23792412 Dec 14 15:46 ls_tidb_install.zipai
-rw-r--r-- 1 root root 443222812 Dec 14 09:33 tidb_install.zip
[root@linux  ]# du -sh *
50M	ls_tidb_install.zipaa
50M	ls_tidb_install.zipab
50M	ls_tidb_install.zipac
50M	ls_tidb_install.zipad
50M	ls_tidb_install.zipae
50M	ls_tidb_install.zipaf
50M	ls_tidb_install.zipag
50M	ls_tidb_install.zipah
23M	ls_tidb_install.zipai
423M	tidb_install.zip
[root@linux  ]# mv ls_tidb_install.zipa* ../ 2
[root@linux  ]# cd ../ 2
[root@linux  2]# du -sh *
50M	ls_tidb_install.zipaa
50M	ls_tidb_install.zipab
50M	ls_tidb_install.zipac
50M	ls_tidb_install.zipad
50M	ls_tidb_install.zipae
50M	ls_tidb_install.zipaf
50M	ls_tidb_install.zipag
50M	ls_tidb_install.zipah
23M	ls_tidb_install.zipai
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

# 合并文件

合并后的文件注意大小应和切割前的文件大小一致(可以看到这里都是423M)

[root@linux]# cat  ls_tidb_install.zipa* > tidb_install.zip
[root@linux]# ll
total 865672
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipaa
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipab
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipac
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipad
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipae
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipaf
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipag
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipah
-rw-r--r-- 1 root root  23792412 Dec 14 15:46 ls_tidb_install.zipai
-rw-r--r-- 1 root root 443222812 Dec 14 15:50 tidb_install.zip
[root@linux]# du -sh *
50M	ls_tidb_install.zipaa
50M	ls_tidb_install.zipab
50M	ls_tidb_install.zipac
50M	ls_tidb_install.zipad
50M	ls_tidb_install.zipae
50M	ls_tidb_install.zipaf
50M	ls_tidb_install.zipag
50M	ls_tidb_install.zipah
23M	ls_tidb_install.zipai
423M	tidb_install.zip

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# 解压验证

[root@linux]# unzip tidb_install.zip 
Archive:  tidb_install.zip
   creating: tidb_install/
  inflating: tidb_install/install.sh  
   creating: tidb_install/include/
  inflating: tidb_install/include/chk_install.sh  
  inflating: tidb_install/include/common.sh  
  inflating: tidb_install/include/Menu.sh  
  inflating: tidb_install/include/sysinfo.sh  
  inflating: tidb_install/include/tidb.sh  
   creating: tidb_install/src/
  inflating: tidb_install/src/tidb-la -linux-amd64.tar.gz  
[root@linux]# ll
total 865672
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipaa
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipab
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipac
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipad
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipae
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipaf
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipag
-rw-r--r-- 1 root root  52428800 Dec 14 15:46 ls_tidb_install.zipah
-rw-r--r-- 1 root root  23792412 Dec 14 15:46 ls_tidb_install.zipai
drwxr-xr-x 4 root root        50 Jul 12 13:05 tidb_install
-rw-r--r-- 1 root root 443222812 Dec 14 15:50 tidb_install.zip
[root@linux]# 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26