Skip to content

split Linux command

The split command in Linux is used to split a large file into smaller parts for easier handling or transferring. It allows you to specify the number of lines or size of each part, making it a versatile tool for managing large amounts of data. By default, split will use a predefined prefix for the smaller files it creates, but you can also specify a custom prefix. Additionally, split offers options for adjusting the number of lines or bytes in each part, allowing for greater control over the splitting process.

split Syntax:

Terminal window
split [OPTION] [INPUT [PREFIX]]

Options:

OptionDescription
-b, —bytes=SIZEput SIZE bytes per output file
-C, —line-bytes=SIZEput at most SIZE bytes of lines per output file
-l, —lines=NUMBERput NUMBER lines/records per output file
-n, —number=CHUNKSgenerate CHUNKS output files; see explanation below
—additional-suffix=SUFFIXappend an additional SUFFIX to file names (default: ‘aa’)
-a, —suffix-length=Nuse suffixes of length N (default 2)
-d, —numeric-suffixes[=FROM]use numeric suffixes instead of alphabetic; from is number (default 0)
-x, —hex-suffixesuse hexadecimal suffixes
-e, —elide-empty-filesdo not generate empty output files with ‘-n’
-u, —unbufferedimmediately copy input to output with ‘-n r/size’ fields
-t, —separator=SUFFIXuse SUFFIX instead of Newline as the record separator
—verboseprint a diagnostic just before each output file is opened
—helpdisplay this help and exit
—versionoutput version information and exit

Parameters:

ParameterDescription
INPUTThe file to split
PREFIXThe prefix for the output file names

split bash Examples:

Split a File into Multiple Pieces

Terminal window
split -b 1M file.txt

Splits the file.txt into multiple pieces, each with a size of 1MB.

Split a File with Custom Prefix

Terminal window
split -d -b 500K file.txt custom_prefix

Splits the file.txt into multiple pieces with a size of 500KB each, using the prefix “custom_prefix”.

Split a File into Equal Parts

Terminal window
split -n 3 file.txt

Divides the file.txt into three equal parts.

Split a File with Specific Number of Lines

Terminal window
split -l 100 file.txt

Splits the file.txt into segments, each containing 100 lines.

Split a File and Specify Suffix Length

Terminal window
split -a 3 -l 200 file.txt

Splits the file.txt into parts, each containing 200 lines, with a suffix length of 3 characters.

Split a File and Set Starting Number

Terminal window
split -l 50 --additional-suffix=".part" -d -a 3 file.txt split_file

Splits the file.txt into parts with 50 lines each, starting with a number sequence and specifying an additional suffix “.part”.

How do I use split in Linux?

To use the split command in Linux, execute the following command:

Terminal window
split --bytes=10M largefile.txt splitfile

What is the purpose of the split command in Linux?

The split command in Linux is used to split a file into smaller parts.

How can I split a file into a specific number of pieces using split in Linux?

You can split a file into a specific number of pieces by specifying the number of lines per output file with the split command, like this:

Terminal window
split -l 100 file.txt output

Can I add a custom prefix to the output files when splitting in Linux?

Yes, you can add a custom prefix to the output files by using the -d flag followed by the desired prefix in the split command, for example:

Terminal window
split -d -l 100 file.txt output_prefix

How can I change the default suffixes generated by split in Linux?

You can change the default suffixes generated by split by using the --suffix-length option followed by the desired length for the suffix in the command, like this:

Terminal window
split --suffix-length=3 file.txt output

Is it possible to split a file based on specific bytes rather than lines in Linux?

Yes, you can split a file based on a specific number of bytes using the --bytes option with the split command in Linux, for example:

Terminal window
split --bytes=100M largefile.bin splitfile

How do I display the help manual for the split command in Linux?

To access the help manual for the split command in Linux, you can use the --help option, like this:

Terminal window
split --help

Can I split a file and specify the maximum number of lines in each output file using split in Linux?

Yes, you can specify the maximum number of lines in each output file by using the -l option followed by the maximum number of lines in the split command, for example:

Terminal window
split -l 200 file.txt output

Applications of the split command

  • Splitting large files into smaller parts for easier transfer or storage
  • Managing file size limitations on certain systems or platforms
  • Creating chunks of data for parallel processing
  • Distributing large datasets for analysis or sharing
  • Archiving and compressing files in chunks for backup or transfer
  • Managing and organizing large volumes of files efficiently