Home  >  Article  >  System Tutorial  >  Detailed explanation of split command in Linux

Detailed explanation of split command in Linux

WBOY
WBOYOriginal
2024-02-21 18:06:031013browse

Detailed explanation of split command in Linux

split is a commonly used command in Linux. It is used to split a file into multiple smaller files. In this article, we will introduce the usage of split command in detail and provide some specific code examples.

1. Command syntax

The basic syntax of the split command is as follows:

split [options] [input file] [output file prefix]

Options:
-e1bb43da1dc495f3a2319be5fe7b6df5: Split the file according to the specified number of lines, the default is 1000 lines.
-a1a92a467ed93314c8305cff19dcf8e18: Specifies the suffix length of the generated file, the default is 2.
-b01ca719230d36350ddb7d75dffd50459: Split the file according to the specified file size, you can use K, M, G and other units.
-d: Use numbers as file suffixes instead of letters.

2. Example demonstration

  1. Split the file according to the number of lines

Suppose there is a file named file.txt with the following content:

A
B
C
D
E
F
G
H
I
J

We can use the following command to split the file into small files with 3 lines each:

split -3 file.txt file_

After executing this command, three files will be generated: file_aa, file_ab, file_ac. Each small file contains three lines of content.

  1. Split files according to file size

If we want to split files according to file size, we can use the following command:

split -b 1k file.txt file_

After executing this command, Generates multiple 1KB sized files. Among them, the first file is file_aa, the second file is file_ab, and so on.

  1. Split files according to file numbers

Use the -d option to use numbers instead of letters for the generated file suffix:

split -d -3 file.txt file_

After executing this command, Three files will be generated: file_01, file_02, file_03.

3. Summary

The split command is a very useful tool that can help us split large files into multiple small files for easy processing and transmission. This article introduces the basic usage of the split command and provides some specific code examples. I hope readers can better understand and apply the split command by reading this article.

The above is the detailed content of Detailed explanation of split command in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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