Linux split Command: Divide Large Files into Smaller Parts

split divides a large file into multiple piece files based on a specified size or number of lines. It is used to split files according to transmission limits or to create batch processing units.

What is the split command?

By default, it splits in units of 1000 lines and uses prefixes/suffixes like xaa. Binary files can be cut in bytes, and they can be restored if concatenated in the original order. Choose a prefix so that the output files do not conflict with existing files.

Basic syntax

split [options] [input_file [output_prefix]]

Installed implementations and options may vary depending on the distribution. Check the current system's description with man split.

Examples

Split by number of lines

Saves to separate files in units of 500 lines.

split -l 500 data.txt part-

Split by size

Creates pieces of about 100 MiB each.

split -b 100M archive.bin archive-part-

Recombine in order

Check the order of the piece names and then join them together.

cat archive-part-* > archive-restored.bin

Checking the files created after splitting

The following command splits four lines into two lines each. Since part-aa and part-ab will be created in the current directory, try it in an empty working directory.

printf 'a\nb\nc\nd\n' | split -l 2 - part-
cat part-aa
cat part-ab

An example of displaying the contents of the two files in order:

a
b
c
d

split itself does not print the filenames. If files with the same name already exist, they may be overwritten, so set a unique prefix. To combine them in the original order, list the filenames in the correct order and use cat part-* > restored_file, then check the size or checksum of the restored result.

Main Options and Format

Options/Format Description
-l N Put N lines in each file.
-b size Specify the maximum byte size of each piece.
-d Use numeric suffixes.
-a N Specify the suffix length as N characters.
--additional-suffix=value Append an additional string to the end of the split file name.

Precautions when using

split -b can split even in the middle of text lines. To preserve lines, check the behavior of -l or GNU -C. When merging pieces, it is safe to select only the files with the corresponding prefix and compare with the original using a hash.

Frequently Asked Questions

Are the original files deleted when split with split?

No. The input file remains as is, and new split files are created.

Official Documentation

The exact behavior of options and differences between implementations can be found in the official documentation for split.

More in This Category
Linux bunzip2 Command: Decompress bzip2 Files

Linux bunzip2 Command: Decompress bzip2 Files

Learn how to decompress bzip2 Files with the Linux bunzip2 command, including practical examples, key options, and important precautions.

Linux apropos Command: Search Commands by Description

Linux apropos Command: Search Commands by Description

Learn how to use the Linux apropos command to find relevant manual pages by searching description keywords, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux journalctl Command: Read systemd Logs

Linux journalctl Command: Read systemd Logs

Learn how to read systemd Logs with the Linux journalctl command, including practical examples, key options, and important precautions.

Linux passwd Command: Change a User Password

Linux passwd Command: Change a User Password

Learn how to change a User Password with the Linux passwd command, including practical examples, key options, and important precautions.

Linux printf Command: Print Values with a Defined Format

Linux printf Command: Print Values with a Defined Format

Learn how to print Values with a Defined Format with the Linux printf command, including practical examples, key options, and important precautions.

Linux fmt Command: Reformat Plain-Text Paragraphs

Linux fmt Command: Reformat Plain-Text Paragraphs

Learn how to reformat Plain-Text Paragraphs with the Linux fmt command, including practical examples, key options, and important precautions.

Linux unalias Command: Remove Command Aliases

Linux unalias Command: Remove Command Aliases

Learn how to use the Linux unalias command to remove one or all aliases from the current shell session, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux top Command: Monitor Processes in Real Time

Linux top Command: Monitor Processes in Real Time

Learn how to monitor Processes in Real Time with the Linux top command, including practical examples, key options, and important precautions.

Linux umask Command: Control Default File Permissions

Linux umask Command: Control Default File Permissions

Learn how to control Default File Permissions with the Linux umask command, including practical examples, key options, and important precautions.

Linux resolvectl Command: Inspect systemd DNS Resolution

Linux resolvectl Command: Inspect systemd DNS Resolution

Learn how to inspect systemd DNS Resolution with the Linux resolvectl command, including practical examples, key options, and important precautions.