linux命令(38):split 分割文件

在Linux下用split进行文件分割:

模式一:指定行数分割文件

对与txt文本文件,可以通过指定分割后文件的行数来进行文件分割。

按照300行进行分割文件:

split -l 300 large_file.txt new_file_prefix
或者
split -300 large_file.txt new_file_prefix

模式二:指定大小分割文件

对于可执行文件等二进制文件,则不能通过文件行数来进行文件分割,此时我们可以指定分割大小来分隔文件。

 指定文件大小(可用:10,10k,10K,10m,10M,10g)

默认格式 10k 分割
$ split -C 10k hello hello
$ ls 
$ hello  helloaa  helloab  helloac  helload  helloae
默认两位数字结尾:40m 分割 $
split -C 40m -d hello hello $ ls $ hello hello00 hello01 hello02 hello03 hello04
三位数字结尾:20g分割 $
split -C 20g -a 3 -d hello hello $ ls $ hello hello000 hello001 hello002 hello003 hello004

对二进制文件我们同样也可以按文件大小来分隔。

在Linux下用cat进行文件合并:

命令:

cat small_files* > large_file

Linx文件分割命令英文释义:

-, read standard input.  Mandatory arguments to long options are mandatory for short options too.  
-a, --suffix-length=N;use suffixes of length N (default 2)   #输出文件后缀长度,默认为:2
-b, --bytes=SIZE ;put SIZE bytes per output file  #按照文件大小分割;
-C, --line-bytes=SIZE ;put at most SIZE bytes of lines per output file  #和-b 比较类似,按照大小分割,但是能保证行的完整性(建议);
-d, --numeric-suffixes  ;use numeric suffixes instead of alphabetic #用数字后缀 
-l, --lines=NUMBER ;put NUMBER lines per output file  #按照行数分割文件,默认1000行一个文件

 

posted on 2017-04-27 17:20  细雨微光  阅读(677)  评论(0编辑  收藏  举报