1、split命令用於分離文件
創建測試文件:
[root@linuxprobe test]# dd if=/dev/zero bs=1024 count=1000000 of=test.txt 1000000+0 records in
1000000+0 records out
1024000000 bytes (1.0 GB, 977 MiB) copied, 47.819 s, 21.4 MB/s [root@linuxprobe test]# ll -h total 977M -rw-r--r--. 1 root root 977M Sep 29 07:27 test.txt [root@linuxprobe test]#
2、基本用法
依據文件大小拆分文件:
split -b 200M test.txt ## -b參數指定文件大小,可以是K、M、G、T等
默認生成了以x開頭的文件。
3、指定輸出文件的前綴,直接在分離文件后加前綴
split -b 200M test.txt result ##直接加前綴result
4、把ab后綴該為數字后綴,直接加 -d:
split -b 200M test.txt result -d ##直接加-d
5、把拆分后的數據合並並校驗
[root@linuxprobe test]# cat result00 result01 result02 result03 result04 > result ## 合並 [root@linuxprobe test]# md5sum result test.txt ##校驗
6、依據行進行拆分
創建測試數據並拆分:
[root@linuxprobe test]# rm -f * [root@linuxprobe test]# seq 50 > test.txt ##測試數據 [root@linuxprobe test]# wc -l test.txt 50 test.txt [root@linuxprobe test]# split -l 10 test.txt test -d ## test為前綴; -d 這只為數字 ,-l 按照每10行進行拆分,l可以省略,直接 -10也沒問題 [root@linuxprobe test]# ls test00 test01 test02 test03 test04 test.txt [root@linuxprobe test]# wc -l *
10 test00 10 test01 10 test02 10 test03 10 test04 50 test.txt 100 total
參考:http://c.biancheng.net/linux/split.html