Skip to content

split MacOS command

The MacOS split command is a useful tool for splitting large files into smaller parts for easier management. This command allows you to specify the number of lines or size of each part, making it convenient for dividing files of any type. By using the split command, you can easily create smaller files that can be more manageable for processing or sharing. Whether you need to split a large log file, extract specific sections of a document, or transfer files in smaller chunks, the split command on MacOS provides a straightforward solution for dividing your files with ease.

split Syntax:

Terminal window
split [option] [parameter]

split Options:

OptionDescription
-a, —suffix-length Nuse suffixes of length N (default 2)
-b, —bytes=SIZEput SIZE bytes per output file (default 1000)
-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
-d, —numeric-suffixesuse numeric suffixes instead of alphabetic
-x, —hex-suffixesuse hexadecimal suffixes instead of alphabetic
-a, —additional-suffix=SUFFIXappend an additional SUFFIX to file names
—filter=COMMANDwrite to shell COMMAND; file name is $FILE
—helpdisplay this help and exit
—versionoutput version information and exit

Parameters:

ParameterDescription
FILEThe file to be split into multiple parts
PREFIXThe prefix for the output files (default: ‘x’)
SUFFIX_LENThe length of the suffixes for the output files (default: 2)
SIZEThe size of each segment in bytes
NUMBERThe number of chunks to split the file into
SUFFIXAn additional suffix to append to the output file names
COMMANDThe shell command to write the output to

split Command Usage Examples:

Split a File into Multiple Parts

Terminal window
split -b 1M file.txt

Splits the file “file.txt” into multiple parts, with each part being 1MB in size.

Split a Large File with a Custom Prefix

Terminal window
split -b 100k largefile.zip prefix_

Divides the file “largefile.zip” into smaller parts, with each part being 100KB and having the prefix “prefix_“.

Split a File with a Specific Number of Parts

Terminal window
split -n 3 file.txt

Splits the file “file.txt” into exactly 3 parts.

Combine the Split Parts Back into the Original File

Terminal window
cat prefix_* > largefile.zip

Combines the split parts (with the prefix “prefix_”) back into the original file “largefile.zip”.

Split a File Using a Specified Number of Bytes as Boundary

Terminal window
split -b 500 file.txt

Divides the file “file.txt” into smaller parts, with each part being 500 bytes in size.

How do I use split in MacOS?

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

Terminal window
split -l 100 myfile.txt

What is the purpose of the split command in MacOS?

The split command is used to split a file into smaller sections for easier handling or transfer.

How can I specify the number of lines for each split file in MacOS?

To specify the number of lines for each split file, use the -l option followed by the desired number of lines. For example:

Terminal window
split -l 500 myfile.txt

Can I add a specific prefix to the split files generated by the split command in MacOS?

Yes, you can add a specific prefix to the split files using the -a (suffix length) and -d (numerical suffixes) options. For example:

Terminal window
split -a 3 -d -l 200 myfile.txt prefix_

How can I combine the split files back into a single file in MacOS?

To combine the split files back into a single file, you can use the cat command followed by the split files in the desired order. For example:

Terminal window
cat x* > combined_file.txt

Is there a way to control the size of the split files generated by the split command in MacOS?

Yes, you can control the size of the split files by using the -b option followed by the desired size. For example, to split a file into 1MB parts:

Terminal window
split -b 1m myfile.txt

How can I specify a custom suffix for the split files in MacOS?

You can specify a custom suffix for the split files by using the -a (suffix length) and -d (numerical suffixes) options. For example:

Terminal window
split -a 2 -d myfile.txt custom_suffix_

Applications of the split command

  • Splitting large files into smaller parts for easier storage or transfer
  • Creating a series of smaller files for easier management
  • Segmenting large datasets for processing or analysis
  • Sharing large documents or videos that need to be divided into smaller pieces