Home > System Tutorial > LINUX > body text

How to use split command in Linux

PHPz
Release: 2024-02-20 09:29:36
Original
1243 people have browsed it

Usage of the split command in Linux, specific code examples

In the Linux system, the split command is a very useful tool. It can be used to split a large file into multiple small files, and can be Split by the specified size, number of lines, or number of bytes. This article will introduce the usage of split command and provide specific code examples.

The basic syntax of the split command is as follows:

split [选项] 文件名 [输出文件名前缀]
Copy after login

Next, we will introduce the various options and usage examples of the split command in detail.

  1. Split the file according to the specified size
    Use option "-b" to split the file according to the specified size. Size can be specified in bytes (default), KB, MB, GB, etc.

    split -b 100M largefile.zip smallfiles
    Copy after login

    The above code splits largefile.zip into multiple small files prefixed with smallfiles according to the size of 100MB.

  2. Split the file according to the specified number of lines
    Use the option "-l" to split the file according to the specified number of lines.

    split -l 1000 logfile.txt smallfiles
    Copy after login

    The above code divides logfile.txt into multiple small files prefixed with smallfiles according to the number of lines of 1000.

  3. Split the file according to the specified number of bytes
    Use option "-C" to split the file according to the specified number of bytes.

    split -C 10k data.txt smallfiles
    Copy after login

    The above code splits data.txt into multiple small files prefixed with smallfiles according to the number of bytes of 10KB.

  4. Split files by file prefix
    Use option "-d" to use numbers as file prefixes instead of the default letter prefix.

    split -b 100M largefile.zip smallfiles -d
    Copy after login

    The above code splits largefile.zip into multiple small files prefixed with numbers according to the size of 100MB.

  5. Specify the suffix of the split file name
    Use option "-a" to specify the suffix length of the split file name, the default is 2.

    split -b 100M largefile.zip smallfiles -a 3
    Copy after login

    The above code splits largefile.zip into multiple small files with a prefix of smallfiles and a suffix length of 3 according to the size of 100MB.

    Through the above examples, we can see that the split command is very flexible in actual use and can split files according to different needs. Please note that the split command will modify the original file, so be sure to back up the file before using it.

    In daily work, the split command can help us better handle large files and improve operating efficiency. I hope this article will help you understand the usage of the split command.

    The above is the detailed content of How to use split command in 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!