linux经常需要处理文件,如果文件比较大,那么需要切分成为若干的小文件再处理。
命令:split
比如有一个文件:
ll -h 1431531915758 -rw-r--r-- 1 ticketdev ticketdev 9.1G May 15 12:18 1431531915758
9.1个G的大小,如果想要切分称为每个文件100M大小,那么需要的命令是:
split -b 100M 1431531915758 split
解释一下参数,-b 文件的大小;split 文件的前缀名称,执行之后的效果:
1431531915758 splitac splitag splitak splitao splitas splitaw splitba splitbe splitbi splitbm splitbq splitbu splitby splitcc splitcg splitck splitco splitcs splitcw splitda splitde splitdi splitdm splitad splitah splital splitap splitat splitax splitbb splitbf splitbj splitbn splitbr splitbv splitbz splitcd splitch splitcl splitcp splitct splitcx splitdb splitdf splitdj splitdnsplitaa splitae splitai splitam splitaq splitau splitay splitbc splitbg splitbk splitbo splitbs splitbw splitca splitce splitci splitcm splitcq splitcu splitcy splitdc splitdg splitdk splitdosplitab splitaf splitaj splitan splitar splitav splitaz splitbd splitbh splitbl splitbp splitbt splitbx splitcb splitcf splitcj splitcn splitcr splitcv splitcz splitdd splitdh splitdl splitdp
发现已经切割成为了若干小文件!
当然如果想要组合的话,那么容易一些的办法是:cat split* > 目标文件名称
如果想要按照每100行来切分文件:split -l 100 file.txt
如果什么参数都不写,默认是每1000行