Home > File & Directory Management > split

split: Split Files into Smaller Pieces

The split command is used to split large files into smaller files based on size or line count. This is very useful when dealing with large files, transferring them over a network, or when you only need to process specific parts.

Overview

split divides an input file into multiple output files based on a specified size (in bytes) or line count. By default, output filenames are generated as 'xaa', 'xab', 'xac', etc., which can be changed using suffix options.

Key Features

  • Split files by specified byte size
  • Split files by specified line count
  • Customize output filename suffixes (numeric, length, additional suffix)
  • Easily recombine split files

Key Options

The main options for the split command control the criteria for splitting files and the naming convention for output files.

Splitting Criteria

Output Filename

Generated command:

Try combining the commands.

Description:

`split` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Learn how to effectively split files through various usage examples of the split command.

Split File into 10MB Chunks

split -b 10M large_file.txt output_prefix_

Splits large_file.txt into files of 10MB each, creating filenames starting with 'output_prefix_' (e.g., output_prefix_aa, output_prefix_ab).

Split File by 1000 Lines

split -l 1000 large_log.txt log_part_

Splits large_log.txt into files with 1000 lines per file, creating filenames starting with 'log_part_'.

Split by 500MB with Numeric Suffix

split -b 500M -d video.mp4 video_part_

Splits video.mp4 into 500MB chunks, using numeric suffixes (00, 01, etc.) in filenames. The default suffix length is 2.

Split by 1GB with Suffix Length 3

split -b 1G -d -a 3 archive.tar archive_part_

Splits archive.tar into 1GB chunks, specifying a suffix length of 3 to generate filenames like 'archive_part_000', 'archive_part_001', etc.

Recombine Split Files

cat output_prefix_* > large_file.txt

Recombines the previously split files starting with 'output_prefix_' back into the original large_file.txt.

Tips & Precautions

Useful tips and points to consider when using the split command.

Recombining Files

Split files can be easily recombined using the `cat` command. For example, use `cat prefix_* > original_file`. The order of the wildcard (`*`) is important, so it's good to verify with `ls` to ensure they are combined in the correct sequence.

  • Use the `cat` command for recombination
  • Be mindful of file order when using wildcards (`*`) (they are sorted alphabetically/numerically)

Disk Space

When splitting files, both the original file and the split files exist simultaneously, so sufficient disk space is required. If you plan to delete the original file after splitting, ensure you have enough space beforehand.

  • More than double the original file size in disk space is needed for the splitting operation
  • Clean up unnecessary files after the operation is complete

Suffix Length

If you anticipate creating a large number of split files, it's advisable to use the `-a` option to specify a sufficiently long suffix length. For instance, if more than 100 files are expected, using `-a 3` allows for suffixes from '000' to '999'.

  • Adjust suffix length with the `-a` option based on the number of split files
  • The default suffix length (2) can create up to 676 files (aa-zz)

Same category commands