How to split files using the split command in Linux (CentOS)

Source: Internet
Author: User
In Linux, if you do not pay attention to it, it may produce a large volume of log files. even if it is several hundred MB, dragging it down for analysis is a waste of time. at this time, if you can cut the file into N small files, take the last file to see the latest log label: CentOS has some means, such as using shell to generate logs every day, etc, but it is not the scope of the discussion here.

The command for cutting large files in CentOS is as follows:


Copy codeThe code is as follows:
Split [OPTION] [INPUT [PREFIX]


The options are as follows:

•-A: specify the suffix length
•-B: The number of bytes per file.
•-D: Use a numeric suffix instead of a letter
•-L: specifies the number of lines per file.

For example, I want to set the suffix length to 2, that is,-a 2. Use the numeric suffix-d. Each file is 10 MB, that is,-B 10 M. The command can be designed as follows:


Copy codeThe code is as follows:
Split-a 2-d-B 10 m/var/lib/mysql/general. log nowamagic


The following cut file is generated in the/root folder:


Copy codeThe code is as follows:
Nowamagic00
Nowamagic01
Nowamagic02
Nowamagic03
Nowamagic04
Nowamagic05
Nowamagic06
Nowamagic07
Nowamagic08
Nowamagic09


Except that the last file is not 10 M (it may happen to be 10 M, but the probability is very small), all others are.

It's easy to understand. let's record it here to help people who need it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.