有时会遇到文件比较大,无法查阅,需要切割才行;
命令参数:
split [选项] [要切割的文件] [输出文件名前缀]

1.首先查看文件大小

ls -lh
//目标文件
android@split:~/home/split$ ls -lh
总用量 3.9G
-rw-rw-r-- 1 android android 3.9G 1月 25 09:52 test.txt

2.切割,他会以a,b,c方式生成文件,小于500m的放到最后一个文件;

//行数切割
split -l 100 test.txt
//指定分割文件的大小为500M
split -b 500m test.txt log_

主要说一下指定分割文件的大小500m方式;

android@split:~/home/split$ split -b 500m test.txt log_

//通过ls -lh查看,非常均匀;
总用量 7.7G
-rw-rw-r-- 1 android android 500M 1月 25 18:20 log_aa
-rw-rw-r-- 1 android android 500M 1月 25 18:20 log_ab
-rw-rw-r-- 1 android android 500M 1月 25 18:20 log_ac
-rw-rw-r-- 1 android android 500M 1月 25 18:20 log_ad
-rw-rw-r-- 1 android android 500M 1月 25 18:20 log_ae
-rw-rw-r-- 1 android android 500M 1月 25 18:20 log_af
-rw-rw-r-- 1 android android 500M 1月 25 18:20 log_ag
-rw-rw-r-- 1 android android 442M 1月 25 18:20 log_ah
-rw-rw-r-- 1 android android 3.9G 1月 25 09:52 test.txt

3.组装文件,可以把自己想组装的文件进行组合;

//如想把log_aa log_ab两个文件组合到一起,test1是新生成的文件,而非原有文件;
android@split:~/home/split$ cat log_aa log_ab* > test1.text

//通过ls -lh查看完全ok;
总用量 1001M
-rw-rw-r-- 1 android android 1000M 1月 25 18:26 test1.text

如果想全部组装起来;

//直接log_它会以a,b,c方式组合到一起;
android@split:~/home/split$ cat log_* > test2.text
android@split:~/home/split$ ls -lh test2.text
-rw-rw-r-- 1 yuanjl yuanjl 1000M 1月

最后修改:2023 年 08 月 04 日
如果觉得我的文章对你有用,请随意赞赏