The split function is used to split files in linux. Its main function is to split large folders. Next I will introduce some examples of splitting large files.
Linux split command
Function Description: cut a file.
Syntax: split [-- help] [-- version] [-<number of rows>] [-B <byte>] [-C <byte>] [-l <number of rows>] [To cut file] [output file name]
Note: split can cut the file into smaller files. By default, each 1000 lines can be cut into a smaller file.
Parameters:
-<Number of rows> or-l <number of rows> specifies the number of rows to be split into a small file.
-B <byte> specifies the number of characters to be split into a small file. Supported units: m, k
-C <byte> is similar to the-B parameter, but the integrity of each line should be maintained whenever possible during cutting.
-- Help: displays help.
-- Version: displays the version information.
[Output file name] sets the prefix file name of the cut file. split will automatically add a number after the prefix file name.
Use split in Linux to split files:
Mode 1: specify the number of lines of files after segmentation
For text files, you can specify the number of lines of the split files to split the files.
Command: split-l 300 large_file.log new_file_prefix
Mode 2: Specify the split File Size
| The Code is as follows: |
Copy code |
Split-B 10 m server. log server_prefix |
We can also separate binary files by file size.
Split file.tar.gz into a file with the "file _" prefix and 10 MB in size.
| The Code is as follows: |
Copy code |
| $ Split-B 10 m file.tar.gz file _ |
Merge files with cat in Linux:
Command: cat small_files *> large_file
Merge and split files
| The Code is as follows: |
Copy code |
$ Cat file _ *> file.tar.gz |