Detailed explanation of file splitting and merging methods under Linux

巴扎黑
Release: 2017-08-17 10:14:22
Original
1806 people have browsed it

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.

Use split to split files under Linux

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

Mode 1: Specify the number of file lines after splitting

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
Copy after login

After segmentation, the suffixes aa, ab, ac...are generated by default and so on. Of course, the suffixes can also be customized.

Mode 2: Specify the file size after splitting

split -b 10m server.log waynelog
Copy after login

We can also separate binary files by file size.

Use cat to merge files under Linux

Command:

cat small_files* > large_file
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!