Linux split拆分文件,linuxsplit拆分


介绍

split可以将一个大文件拆分成指定大小的多个文件,并且拆分速度非常的快,拆分一个1G大小的文件花费不到1S的时间,如果手工在windows上面进行操作估计得卡死。

 

 

选项

Usage: split [OPTION]... [INPUT [PREFIX]]
Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default
size is 1000 lines, and default PREFIX is `x'.  With no INPUT, or when INPUT
is -, 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) 指定拆分文件的后缀长度
  -b, --bytes=SIZE        put SIZE bytes per output file 按字节拆分,默认单位字节
  -C, --line-bytes=SIZE   put at most SIZE bytes of lines per output file  指定单行的最大大小,默认单位字节
  -d, --numeric-suffixes  use numeric suffixes instead of alphabetic 用数字作为拆分文件的后缀
  -l, --lines=NUMBER      put NUMBER lines per output file  按行数进行拆分
      --verbose           print a diagnostic just before each
                            output file is opened
      --help     display this help and exit
      --version  output version information and exit

SIZE may be (or may be an integer optionally followed by) one of following:
KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y. 可以用后缀指定其它的单位

Report split bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'split invocation'

 

实例

[root@localhost test]# more test
a
b
c
d
e
f
g

1.根据行拆分

每3行拆分成一个文件,拆分后的文件名以name开头,以数字作为后缀后缀长度为1

split -l 3 test -d -a 1 name
[root@localhost test]# ll
total 16
-rw-r--r--. 1 root root  6 Oct  9 19:12 name0
-rw-r--r--. 1 root root  6 Oct  9 19:12 name1
-rw-r--r--. 1 root root  2 Oct  9 19:12 name2
-rw-r--r--. 1 root root 14 Oct  9 19:07 test

2.按字节进行拆分

每三个字节拆分成一个文件,默认不加单位就是字节,也可以带单位比如KB,MB等

split -b 3 test -d -a 1 new
[root@localhost test]# ls -l new*
-rw-r--r--. 1 root root 3 Oct  9 19:13 new0
-rw-r--r--. 1 root root 3 Oct  9 19:13 new1
-rw-r--r--. 1 root root 3 Oct  9 19:13 new2
-rw-r--r--. 1 root root 3 Oct  9 19:13 new3
-rw-r--r--. 1 root root 2 Oct  9 19:13 new4

 

总结

 spit命令很实用,比如导入数据时将文件进行拆分并发导入会快很多。

 

 

 

 

备注:

    作者:pursuer.chen

    博客:http://www.cnblogs.com/chenmh

本站点所有随笔都是原创,欢迎大家转载;但转载时必须注明文章来源,且在文章开头明显处给明链接。

《欢迎交流讨论》

相关内容