Linux online course

How to Split a File into Multiple Files in Linux

Learn how to use the Linux split command to divide files by byte size or line count, inspect the results, choose output names, and troubleshoot common problems.

The Linux split command divides one input file into multiple output files. This is useful when a file is too large to transfer conveniently, when data must be processed in batches, or when a large text file needs to be separated into smaller pieces.

This lesson assumes that you can open a terminal, navigate directories, and work with file paths. For background, see File Structure in Linux and Bourne Again Shell Bash.

What the split Command Does

split reads one input file and creates several output files from it. An input file is the original file supplied to the command. Each generated file contains one portion of the original content.

Common reasons to split a file include:

  • Dividing a large file into smaller pieces for transfer.
  • Processing a dataset in manageable batches.
  • Separating a large log or text file into smaller files.
  • Meeting a file-size limit imposed by a storage or transfer system.

Basic split Syntax

The general command structure is:

split [options] input_file output_prefix

The input_file is the source file being divided. The output prefix is the filename beginning used for every generated part.

For example:

split file.txt new_file_

Here, file.txt is the source and new_file_ is the output prefix.

Default Output Names

By default, split appends alphabetical suffixes to the prefix. The first files normally end with aa, ab, and ac, followed by later alphabetic combinations as needed.

new_file_aa
new_file_ab
new_file_ac

Choose the prefix carefully. A clear, unique prefix makes the parts easy to identify. Avoid reusing a prefix in a directory that already contains matching files, because generated names can be confused with older output and existing matching files may be replaced by the command.

Splitting by Byte Size

A byte is a unit used to measure file data. Use the -b option to define the maximum byte size of each output part.

split -b SIZE INPUT_FILE OUTPUT_PREFIX

To create chunks of 55 bytes from file.txt:

split -b 55 file.txt new_file_

This creates files such as new_file_aa and new_file_ab, with additional parts if the input requires them.

Many implementations, including GNU split, accept size suffixes such as K, M, and G:

split -b 10M large-data.bin data-part-

Size suffix support and its exact interpretation can vary between operating systems, so check the local manual if a suffix is rejected. You can usually view command help with:

split --help

Splitting by Line Count

A line is a newline-delimited text record. Use the -l option to place a specified number of lines in each output file.

split -l LINE_COUNT INPUT_FILE OUTPUT_PREFIX

To place one line in each output file:

split -l 1 file.txt line_

The result includes names such as line_aa and line_ab, with one input line in each part.

For a log file, create parts containing up to 1,000 complete lines:

split -l 1000 application.log application-part-

The final output file can contain fewer lines than requested. This happens when the total number of input lines is not evenly divisible by the selected line count, and it is normal.

Common split Options

OptionPurposeExampleWhen to use it

-b SIZE — Creates byte-based parts — split -b 10M input.bin part- — Use when an output-size limit is the main requirement.

-l NUMBER — Creates parts with a specified number of lines — split -l 1000 input.log part- — Use for text files and line-oriented logs or datasets.

Byte-Based vs. Line-Based Splitting

MethodPreserves complete linesControls output file sizeBest for

Byte-based splitting — No; boundaries can occur inside lines or characters — Yes, up to the selected byte size — File-size limits and arbitrary binary data.

Line-based splitting — Yes, for newline-delimited text — No exact byte-size limit — Logs, text files, and datasets whose records must stay whole.

Choose -b when the size of each part matters most. Choose -l when preserving complete lines or records matters most.

Inspecting Generated Files

Use ls with a wildcard to list files created from a prefix and display their sizes:

ls -lh new_file_*

The wildcard * matches the rest of each generated filename. The -l option provides detailed information, and -h displays sizes in a human-readable form.

For text output, inspect a complete part with cat:

cat line_aa

For larger parts, use less so you can scroll without printing the entire file at once:

less application-part-aa

Use head to inspect the beginning of a part:

head application-part-aa

The nl command displays text with line numbers. Number the original file before validating a line-based split:

nl -ba file.txt

Line numbering helps you compare the expected boundaries with the first and last lines in each generated part. For example, if a part is meant to contain one line, its content should correspond to exactly one numbered line from the source.

Practical Workflow

  1. Confirm the source filename and location.
  2. Choose whether the requirement is a byte limit or complete-line preservation.
  3. Select a unique output prefix, preferably in a suitable working directory.
  4. Run split with -b or -l.
  5. List the results with ls -lh.
  6. Inspect representative parts with head, less, cat, or nl.

Troubleshooting

The Output Names Are Unexpected

split automatically adds suffixes to the output prefix. If the command uses new_file_, names such as new_file_aa and new_file_ab are expected. Use a clear prefix and verify the results with:

ls -lh new_file_*

A Text Record Is Cut Across Two Parts

This usually means the file was split with -b. Byte splitting follows byte counts rather than line boundaries. Run the command with -l when each complete line must remain together.

The Last Part Is Smaller

The final part is smaller when the input size or line count is not evenly divisible by the selected chunk size. This is expected. Inspect the last file to confirm that it contains the remaining content.

The Source File Cannot Be Read

Check that the path and filename are correct, then inspect permissions:

ls -l INPUT_FILE

A missing file, an incorrect directory, or insufficient read permission can prevent split from opening the source.

Existing Files Were Replaced or Mixed with New Output

The output prefix may have been reused in a directory containing matching files. Choose a unique prefix and, when appropriate, work in a dedicated output directory. List matching names before running the command so you know what already exists.

Key Points

  • split creates multiple output files from one input file.
  • The syntax is split [options] input_file output_prefix.
  • Generated names normally use suffixes beginning with aa, ab, and ac.
  • Use -b for byte-based parts and file-size requirements.
  • Use -l for complete-line parts in text files and logs.
  • The last part may be smaller than the other parts.
  • Use ls, cat, less, head, and nl to inspect and verify the output.

For related file inspection tasks, see Determine File Type, Search For Text Strings Using Grep, and Show The Full Path Of Shell Commands.