大文件切割技巧

2022-10-27 13:41:33 浏览数 (3)

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

# 分切文件

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

代码语言:javascript复制
[root@summer test]# ll
total 432836
-rw-r--r-- 1 root root 443222812 Dec 14 09:33 tidb_install.zip
[root@summer test]# du -sh *
423M	tidb_install.zip
[root@summer test]# cat tidb_install.zip | split -b 50m - ls_tidb_install.zip 
[root@summer test]# 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 09:33 tidb_install.zip
[root@summer test]# 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@summer test]# mv ls_tidb_install.zipa* ../test2
[root@summer test]# cd ../test2
[root@summer test2]# 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)

代码语言:javascript复制
[root@summer test2]# cat  ls_tidb_install.zipa* > tidb_install.zip
[root@summer test2]# 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@summer test2]# 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

# 解压验证

代码语言:javascript复制
[root@summer test2]# 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-latest-linux-amd64.tar.gz  
[root@summer test2]# 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@summer test2]# 

1 人点赞