一、常用拆分
- 按行拆分
# 拆分文件为指定行数
$ split -d -l 10000 -a 2 file.txt out_
$ ll
-rw-r--r-- 1 xxxx staff 369K 10 18 17:34 file.txt
-rw-r--r-- 1 xxxx staff 68K 10 18 17:44 out_00
-rw-r--r-- 1 xxxx staff 68K 10 18 17:44 out_01
-rw-r--r-- 1 xxxx staff 68K 10 18 17:44 out_02
-rw-r--r-- 1 xxxx staff 68K 10 18 17:44 out_03
-rw-r--r-- 1 xxxx staff 68K 10 18 17:44 out_04
-rw-r--r-- 1 xxxx staff 27K 10 18 17:44 out_05
- 按大小拆分
# 拆分文件为指定大小
$ split -d -b 100K -a 1 file.txt out_
$ ll
-rw-r--r-- 1 xxxx staff 369K 10 18 17:34 file.txt
-rw-r--r-- 1 xxxx staff 100K 10 18 17:42 out_0
-rw-r--r-- 1 xxxx staff 100K 10 18 17:42 out_1
-rw-r--r-- 1 xxxx staff 100K 10 18 17:42 out_2
-rw-r--r-- 1 xxxx staff 69K 10 18 17:42 out_3
- 按数拆分
# 拆分文件为指定数量
$ split -d -n 6 -a 1 file.txt out_
$ ll
-rw-r--r-- 1 xxxx staff 369K 10 18 17:34 file.txt
-rw-r--r-- 1 xxxx staff 62K 10 18 17:48 out_0
-rw-r--r-- 1 xxxx staff 62K 10 18 17:48 out_1
-rw-r--r-- 1 xxxx staff 62K 10 18 17:48 out_2
-rw-r--r-- 1 xxxx staff 62K 10 18 17:48 out_3
-rw-r--r-- 1 xxxx staff 62K 10 18 17:48 out_4
-rw-r--r-- 1 xxxx staff 62K 10 18 17:48 out_5
二、参数说明
-d 使用数字代替字母作为后缀。
-l 行数
按行数拆分。
-b 大小[K|k|M|m|G|g]
按大小拆分。单位:Kk -> KB,Mm -> MB,Gg -> GB。
-n 个数
按个数拆分。
-a 后缀长度
使用指定的后缀长度。
三、参考详细
NAME
split – split a file into pieces
SYNOPSIS
split -d [-l line_count] [-a suffix_length] [file [prefix]]
split -d -b byte_count[K|k|M|m|G|g] [-a suffix_length] [file [prefix]]
split -d -n chunk_count [-a suffix_length] [file [prefix]]
split -d -p pattern [-a suffix_length] [file [prefix]]
DESCRIPTION
The split utility reads the given file and breaks it up into files of 1000 lines each (if no options are
specified), leaving the file unchanged. If file is a single dash (‘-’) or absent, split reads from the
standard input.
The options are as follows:
-a suffix_length
Use suffix_length letters to form the suffix of the file name.
-b byte_count[K|k|M|m|G|g]
Create split files byte_count bytes in length. If k or K is appended to the number, the file is
split into byte_count kilobyte pieces. If m or M is appended to the number, the file is split
into byte_count megabyte pieces. If g or G is appended to the number, the file is split into
byte_count gigabyte pieces.
-d Use a numeric suffix instead of a alphabetic suffix.
-l line_count
Create split files line_count lines in length.
-n chunk_count
Split file into chunk_count smaller files. The first n - 1 files will be of size (size of file /
chunk_count ) and the last file will contain the remaining bytes.
-p pattern
The file is split whenever an input line matches pattern, which is interpreted as an extended
regular expression. The matching line will be the first line of the next output file. This
option is incompatible with the -b and -l options.