![]() |
VOOZH | about |
The split command lets you break a large file into smaller chunks for easier storage, transfer, or analysis. By default it creates 1000-line pieces and auto-names them with alphabetic suffixes like PREFIXaa, PREFIXab (the default prefix is x, but you can choose your own, e.g., split big.log part).
Split file into short files. Assume a file name with name index.txt. Use below split command to break it into pieces.
Command:
split index.txtOutput:
π Split-file-into-short-filesindex.txt is divided into two smaller files named xaa and xab.x, resulting in the output files being named xaa and xab.split CommandHere are some commonly used options in split command
Syntax:
split [options] name_of_file prefix_for_new_files-l)This option allows you to divide a file into smaller parts based on a specific number of lines. Each output file will contain the given number of lines.
Example:
split -l 4 index.txt split_fileπ splitting the file based on number of linesindex.txt into smaller files (split_fileaa, split_fileab, etc.), each containing 4 lines.--verbose)--verbose option displays a message every time a new split file is created.Example:
split index.txt -l 4 --verboseπ Split-command-with-verbose-optionNote:
-b)-b option splits a file into smaller chunks based on size (bytes, KB, MB, etc.).Example:
split -b 16 index.txt indexπ Split-file-size-using-bytes-optionSplits index.txt into multiple files (indexaa, indexab, etc.), each containing 16 bytes of data.
-a)xaa, xab).-a option lets you customize the suffix length.Example:
split -l 4 -a 4 index.txtπ Change-in-suffix-lengthCreates files like xaaaa, xaaab, xaaac, etc. with a 4-character suffix.
-d)xaa, xab, etc.).-d option changes them to numeric suffixes (x00, x01, x02, etc.).Example:
split -l 4 -d index.txtπ Split-files-created-with-numeric-suffixx00, x01, x02, etc.-n)-n option divides a file into a specific number of equal parts. split -n 3 index.txtπ Create-n-chunks-output-filesindex.txt into 3 equal parts, regardless of file size or line count.split -l 4 index.txt split_index_π Split-file-with-customize-suffixsplit_index_aa, split_index_ab, etc.-e)-e option prevents creation of zero-byte files.split -l 4 -e index.txtπ Avoid-zero-sized-split-files-n 2)-n 2.split -n 2 index.txtπ Split-file-into-two-files-of-equal-lengthindex.txt.