
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Split or Break Large Files into Pieces in Linux
To split large files into small pieces, we use the split command in the Linux operating system.The split command is used to split or break large files into small pieces in the Linux system. By default, it generates output files of a fixed size, the default lines are 1000 and the default prefix would be ‘x’.
For example, if the output file is not given, the default filename would be xaa, xab, etc. When a – (hyphen) is used instead of an input file then the data is derived from standard input.
Syntax
The general syntax of the split command as follows.
split [OPTION]... [FILE [PREFIX]]
Brief description of options available in the split command.
Sr.No. | Option & Description |
---|---|
1 |
-a, --suffix-length=N Generate suffixes of length N, the default length is 2. |
2 |
--additional-suffix=SUFIX Append an addition suffix to the filenames. |
3 |
-b, --byte=SIZE Put SIZE bytes per output file. |
4 |
-C, --line-bytes=SIZE Put at most SIZE bytes of records per output file. |
5 |
-d Use numeric suffixes starting at 0 instead of by default alphabetic. |
6 |
-x Use hex suffixes starting at 0, not alphabetic. |
7 |
--hex-suffixes [=FROM] Same as -x option, but allow to set the start value. |
8 |
-e, --elide-empty-files Do not generate empty files with -n option. |
9 |
--filter=COMMAND Write to shell command, and the file name is $FILE |
10 |
-l, --line=NUMBER Put NUMBER lines/records per output file. |
11 |
--help Display this help and exit |
12 |
--version Output version information and exit |
Example
To break or split a large file into small pieces, we use the split command in the Linux system as shown below.
$ split text.txt
After executing the above command, the file text.txt will be broken into two pieces xaa and xab in our file system.
To split large files into small pieces, we use the -l option with the split command in the Linux system as shown below.
Suppose we want to split a file into four pieces based on line then, we have to execute the below command.
$ split -l 4 text.txt
To split a file into small pieces and print what is being done, we use the --verbose option with the split command in the Linux system.
$ split --verbose text.txt Creating file ‘xaa’ Creating file ‘xab’
To check more information and option with descriptions about the split command, we use the --help option with the split command as shown below.
$ split --help
To check in which version the split command is working, we use the --version option with the split command in the Linux system as shown below.
$ split --version