Linux training tutorial How to partition large files under Linux system

Source: Internet
Author: User

To partition large files in Linux , such as a 5GB log file, it is necessary to divide it into smaller files, which are segmented to facilitate reading by the normal text editor.

Sometimes, the need to transfer large files of 20gb ,Linux training

Tutorial pieces to another server, you also need to split it into multiple files, which makes it easy to transfer data.

The following five different examples, to explain how to partition large files under Linux for your reference.

Example 1, separated by each file.

  The split command splits the file into each file and the file name is [ prefix ]aa,[ prefix ]ab, [ prefix ]ac , etc.]. The default prefix is X, and the number of rows per file is.

Command:

Copy the code code as follows :

  $ split Mylog-l 1000

  $ wc-l *

  4450 MyLog

  Xaa

  Xab

  Xac

  Xad

  Xae

Example 2, 20MB segmentation per file

Split files into multiple 20MB files with the- b option.

Command:

Copy the code code as follows :

  $ split-b 20M Logdata

  $ LS-LH | Tail-n +2

  -RW-------1 Sathiyasathiya 102M 18:47 logdata

  -RW-------1 Sathiyasathiya 20M 19:20 XAA

  -RW-------1 Sathiyasathiya 20M 19:20 xab

  -RW-------1 Sathiyasathiya 20M 19:20 xac

  -RW-------1 Sathiyasathiya 20M 19:20 xad

  -RW-------1 Sathiyasathiya 20M 19:20 xae

  -RW-------1 Sathiyasathiya 1.6M Jul 19:20 xaf

Example 3, specifying a prefix partition for each file 50MB

Use the –bytes option to split the file into multiple 50MB files,–bytes like the- b option, specifying a prefix in the second parameter.

Command:

Copy the code code as follows :

  $ split--bytes=50m Logdatamydatafile

  $ ls-lh

  Total 204M

  -RW-------1 Sathiyasathiya 102M 18:47 logdata

  -RW-------1 Sathiyasathiya 50M 19:23 MYDATAFILEAA

  -RW-------1 Sathiyasathiya 50M 19:23 Mydatafileab

  -RW-------1 Sathiyasathiya 1.6M 19:23 MYDATAFILEAC

Example 4, based on the row number split file

Use the- l option to specify the number of rows to split the file into files of the same number of rows.

Command:

Copy the code code as follows :

  $ wc-l Testfile

  2591 testfile

  $ split-l Testfileimportantlog

  $ wc-l *

  Importantlogaa

  1091 Importantlogab

  2591 testfile

Example 5, naming the split file with a numeric suffix

Use the- d option to specify a suffix number, such as 00,01,02, instead of Aa,ab,ac.

Command:

Copy the code code as follows :

  $ split-d Testfile

  $ ls

  Testfile x00 x01 x02

Available options

Copy the code code as follows :

Short option long option option description

  The -b–bytes=size size value is the amount of each output file, in bytes.

  -c–line-bytes=size The maximum number of bytes per single line in each output file.

  -d–numeric-suffixes use numbers as suffixes.

  The -l–lines=number number value is the column size for each output file. </p> <p> short option long option option description

  The -b–bytes=size size value is the amount of each output file, in bytes.

  -c–line-bytes=size The maximum number of bytes per single line in each output file.

  -d–numeric-suffixes use numbers as suffixes.

  The -l–lines=number number value is the column size for each output file.



Linux training tutorial How to partition large files under Linux system

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.