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 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.

Linux alias Command: Create Command Shortcuts

Linux alias Command: Create Command Shortcuts

Learn how to use the Linux alias command to create, inspect, and make shell command aliases persistent, with essential options, practical examples, output interpretation, and common troubleshooting tips.

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 renice Command: Change the Priority of a Running Process

Linux renice Command: Change the Priority of a Running Process

Learn how to change the Priority of a Running Process with the Linux renice command, including practical examples, key options, and important precautions.

Linux Tutorial / Hard Links vs. Symbolic Links in Linux: Differences and Examples

Linux Tutorial / Hard Links vs. Symbolic Links in Linux: Differences and Examples

Compare hard and symbolic links through inode and path behavior, then create both kinds of link and observe what happens when the original name changes.

Linux unxz Command: Decompress xz Files

Linux unxz Command: Decompress xz Files

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

Linux whereis Command: Locate Binaries, Source, and Man Pages

Linux whereis Command: Locate Binaries, Source, and Man Pages

Learn how Linux whereis locates binaries, source files, and manual pages, limits each search type, lists effective paths, and differs from which and find.

Linux modinfo Command: Inspect Kernel Module Details

Linux modinfo Command: Inspect Kernel Module Details

Learn how to inspect Kernel Module Details with the Linux modinfo command, including practical examples, key options, and important precautions.

Linux column Command: Format Text as a Table

Linux column Command: Format Text as a Table

Learn how to format Text as a Table with the Linux column command, including practical examples, key options, and important precautions.

Linux info Command: Browse GNU Documentation

Linux info Command: Browse GNU Documentation

Learn how to use the Linux info command to browse hierarchical GNU manuals and navigate Info nodes, with essential options, practical examples, output interpretation, and common troubleshooting tips.