Linux Split Command Explained with Different Examples
LinuxThe split command in Linux is a command line utility that is used to split a file into multiple parts. It can be used to break large files into smaller chunks, making them easier to transport or store. The split command is part of the GNU core utilities package, which is installed by default on most Linux distributions.
Here at Fixwebnode, we shall look into the basics of the split command, including its syntax, options, and examples.
Table of contents [Show]
What is the Syntax of the split command ?
The basic syntax of the split command is as follows:
$ split [OPTIONS] [INPUT_FILE] [OUTPUT_FILE_PREFIX]
The split command has several command line options that you can use to customize its operation:
- -n : This option is used to specify the number of lines to be split.
- -l : This option is used to specify the number of lines per output file.
- -b : This option is used to specify the number of bytes per output file.
- -a : This option is used to specify the number of characters to be used in the output file prefix.
Examples of using Split Command
Here are some examples of how to use the split command.
1. Split a file into two parts
To split a file into two parts, you can use the following command:
$ split -n 2 input_file output_file
This command will split the input file into two parts, and each part will have the same number of lines. The output files will be named output_fileaa and output_fileab.
2. Split a file into multiple parts
To split a file into multiple parts, you can use the following command:
$ split -l 10 input_file output_file
This command will split the input file into multiple parts, each with 10 lines. The output files will be named output_fileaa, output_fileab, output_fileac, and so on.
3. Split a file into parts of a certain size
To split a file into parts of a certain size, you can use the following command:
$ split -b 1024 input_file output_file
This command will split the input file into parts of size 1024 bytes. The output files will be named output_fileaa, output_fileab, output_fileac, and so on.
4. Split a file with a custom file prefix
To split a file with a custom file prefix, you can use the following command:
$ split -a 3 input_file custom_prefix
This command will split the input file into parts, and each part will have a custom prefix of 3 characters. The output files will be named custom_preaaa, custom_preaab, custom_preaac, and so on.
[Need help in fixing Linux system issues ? We are available. ]
This article covers the basics of the split command in Linux. We also looked at some examples of how to use its Options.