Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to divide large files under linux system

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to divide large files under the linux system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

To split a large file, such as a 5gb log file, in linux, you need to divide it into multiple small files, which can be easily read by an ordinary text editor.

Sometimes, you need to transfer a large file of 20gb to another server, and you also need to split it into multiple files to facilitate data transfer.

Here are five different examples to explain the method of dividing large files under Linux for your reference.

Example 1. Split by 1000 lines per file

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

Command:

The code is as follows:

$split mylog-l 1000

$wc-l *

4450 mylog

1000 xaa

1000 xab

1000 xac

1000 xad

450 xae

Example 2. Split by 20MB of each file

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

Command:

The code is as follows:

$split-b 20m logdata

$ls-lh | tail-n + 2

-rw- 1 sathiya sathiya 102m Jul 25 18:47 logdata

-rw- 1 sathiya sathiya 20m Jul 25 19:20 xaa

-rw- 1 sathiya sathiya 20m Jul 25 19:20 xab

-rw- 1 sathiya sathiya 20m Jul 25 19:20 xac

-rw- 1 sathiya sathiya 20m Jul 25 19:20 xad

-rw- 1 sathiya sathiya 20m Jul 25 19:20 xae

-rw- 1 sathiya sathiya 1.6m Jul 25 19:20 xaf

Example 3. Specify a prefix split with each file 50MB

Use the-bytes option to split the file into multiple 50MB files, and-bytes is similar to the-b option, specifying the prefix in the second parameter.

Command:

The code is as follows:

$split-bytes=50M logdata mydatafile

$ls-lh

Total 204M

-rw- 1 sathiya sathiya 102m Jul 25 18:47 logdata

-rw- 1 sathiya sathiya 50m Jul 25 19:23 mydatafileaa

-rw- 1 sathiya sathiya 50m Jul 25 19:23 mydatafileab

-rw- 1 sathiya sathiya 1.6m Jul 25 19:23 mydatafileac

Example 4. Split files based on the number of lines

Use the-l option to specify the number of lines to split the file into multiple files with the same number of lines.

Command:

The code is as follows:

$wc-l testfile

2591 testfile

$split-l 1500 testfile importantlog

$wc-l *

1500 importantlogaa

1091 importantlogab

2591 testfile

Example 5. Name the split file with a numeric suffix

Use the-d option to specify a suffix as a number, such as 00B01Phone02... instead of aa,ab,ac.

Command:

The code is as follows:

$split-d testfile

$ls

Testfile x00 x01 x02

Available option

The code is as follows:

Short option long option description

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

-C-line-bytes=SIZE the maximum number of byte per line in each output file.

-d-numeric-suffixes uses numbers as suffixes.

The-l-lines=NUMBER NUMBER value is the number of columns per output file.

Short option long option description

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

-C-line-bytes=SIZE the maximum number of byte per line in each output file.

-d-numeric-suffixes uses numbers as suffixes.

The-l-lines=NUMBER NUMBER value is the number of columns per output file.

This is the end of the content of "how to divide large files under the linux system". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report