TrumanWong

split

Split files of any size

Supplementary instructions

split command can split a large file into many small files. Sometimes it is necessary to split the file into smaller fragments, such as to improve readability, generate logs, etc.

Options

-b: The value is the size of each output file, in bytes.
-C: The maximum number of bytes in a single line in each output file.
-d: Use numbers as suffix.
-l: The value is the number of lines in each output file.
-a: Specify the suffix length (default is 2).

Example

Generate a test file of size 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

Use the split command to split the date.file created above into small files of 10KB size:

[root@localhost split]# split -b 10k date.file
[root@localhost split]# ls
date.file xaa xab xac xad xae xaf xag xah xai xaj

The file is split into multiple suffix files with letters. If you want to use a numeric suffix, you can use the -d parameter, and you can use -a length to specify the length of the suffix:

[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

Specify the file name prefix for the split files:

[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

Use the -l option to split the file based on the number of lines in the file, for example, split the file into small files containing 10 lines each:

split -l 10 date.file