Linux文件拆分命令 spilt

linux split 命令

  功能说明:切割文件。

  语  法:split [--help][--version][-<行数>][-b <字节>][-C <字节>][-l <行数>][要切割的文件][输出文件名]

  补充说明:split可将文件切成较小的文件,预设每1000行会切成一个小文件。

  参  数:

  -<行数>或-l<行数>  指定每多少行就要切成一个小文件。

  -b<字节>  指定每多少字就要切成一个小文件。支持单位:m,k

  -C<字节>  与-b参数类似,但切割时尽量维持每行的完整性。

  --help  显示帮助。

  --version  显示版本信息。

[输出文件名]  设置切割后文件的前置文件名,split会自动在前置文件名后再加上编号。


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'

实例 

生成一个大小为100KB的测试文件: 

[root@localhost split]# dd if=/dev/zero bs=100k count=1 of=date.file 

1+0 records in 

1+0 records out 

102400 bytes (102 kB) copied, 0.00043 seconds, 238 MB/s

使用split命令将上面创建的date.file文件分割成大小为10KB的小文件:
[root@localhost split]# split -b 10k date.file

[root@localhost split]# ls 

date.file xaa xab xac xad xae xaf xag xah xai xaj

文件被分割成多个带有字母的后缀文件,如果想用数字后缀可使用-d参数,同时可以使用-a length来指定后缀的长度: 

[root@localhost split]# split -b 10k date.file -d -a 3 

[root@localhost split]# ls 

date.file x000 x001 x002 x003 x004 x005 x006 x007 x008 x009

 为分割后的文件指定文件名的前缀:

[root@localhost split]# split -b 10k date.file -d -a 3 split_file

[root@localhost split]# ls 

date.file split_file000 split_file001 split_file002 split_file003 split_file004 split_file005 split_file006 split_file007 split_file008 split_file009 

使用-l选项根据文件的行数来分割文件,例如把文件分割成每个包含10行的小文件: 

split -l 10 date.file



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




  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值