简体   繁体   English

Linux 按块分割大文件

[英]Linux split big files by chunks

I have a big file (15GB) located in my host.我的主机中有一个大文件(15GB)。

I want to split this file into chunks of 200MB.我想将此文件拆分为 200MB 的块。

Currently, I do it using:目前,我使用:

split -a 3 -d -b 200MB my_big_file /tmp/chunk_

The problem is that for now I have only 10GB free space, I want to split it by offset, meaning that the first step is to read from the big file 7GB, split it using split , remove the split files and then split from 7GB to 15GB.问题是现在我只有 10GB 可用空间,我想按偏移量拆分它,这意味着第一步是从大文件 7GB 中读取,使用split将其拆分,删除拆分文件,然后从 7GB 拆分为15GB。

How can I do it?我该怎么做?

Use dd command to read the file and specify value of block size as 1 and value of count as exactly half the number of bytes in file in order to read first half of file and redirect the output of dd command to split command, like this:使用dd命令读取文件并将块大小的值指定为1 ,将count指定为文件中字节数的一半,以便读取文件的前半部分并将dd命令的输出重定向到split命令,如下所示:

(Assumptions: big_file is name of your 15GB file and its size, in bytes, is exactly 15GB ) : (假设: big_file15GB文件的名称,其大小(以字节为单位)正好是15GB

# dd if=big_file bs=1 count=8053063680 | split -a 3 -d -b 200MB - /tmp/chunk_

This will split the first half of file in chunks of 200MB .这会将文件的前半部分分成200MB的块。

Note that 8053063680 is half of number of bytes in 15GB ( 16106127360 bytes).请注意, 805306368015GB中字节数的一半( 16106127360字节)。

For second half下半场

# dd if=big_file bs=1 skip=8053063680 count=8053063680 | split -a 3 -d -b 200MB - /tmp/chunk_

Again, be sure about the exact size of your file in bytes and based on that give value to count and skip .同样,请确保文件的确切大小(以字节为单位),并根据该大小为countskip赋值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM