Home > Article > Operation and Maintenance > Detailed explanation of file splitting and merging methods under Linux
File splitting under Linux can be achieved through the split command. You can split a large file into multiple files of specified sizes, and the splitting speed is very fast. You can specify two modes: split by line number and split by size. . File merging under Linux can be achieved through the cat command, which is very simple.
Read the help document first
Usage: split [OPTION]... [INPUT [PREFIX]]
Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default
size is 1000 lines, and default PREFIX is `x'. With no INPUT, or when INPUT
is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
-a, --suffix-length=N use suffixes of length N (default 2 ) Specify the suffix length of the split file
-b, --bytes=SIZE Put SIZE bytes per output file Split by bytes, the default unit is bytes
-C, --line -bytes=SIZE put at most SIZE bytes of lines per output file Specify the maximum size of a single line, the default unit is bytes
-d, --numeric-suffixes use numeric suffixes instead of alphabetic Use numbers as a split file Suffix
-l, --lines=NUMBER put NUMBER lines per output file Split by number of lines
--verbose print a diagnostic just before each
output file is opened
--help display this help and exit
--version output version information and exit
For txt text files, you can split the file by specifying the number of lines in the split file.
Command:
split -l 300 large_file.txt new_file_prefix
After segmentation, the suffixes aa, ab, ac...are generated by default and so on. Of course, the suffixes can also be customized.
split -b 10m server.log waynelog
We can also separate binary files by file size.
Command:
cat small_files* > large_file
The above is the detailed content of Detailed explanation of file splitting and merging methods under Linux. For more information, please follow other related articles on the PHP Chinese website!