The most effective solution is very close to the content of this answer:
# Create archives
tar cz my_large_file_1 my_large_file_2 | split -b 1024MiB - myfiles_split.tgz_
# Uncompress
cat myfiles_split.tgz_* | tar xz
This solution avoids the need to use an intermediate large file when (de)compressing. Use the tar -C option to use a different directory for the resulting files. btw if the archive consists from only a single file, tar could be avoided and only gzip used:
gzip -c file.orig > file.gz
CHUNKSIZE=1073741824
PARTCNT=$[$(stat -c%s file.gz) / $CHUNKSIZE]
# the remainder is taken care of, for example for
# 1 GiB + 1 bytes PARTCNT is 1 and seq 0 $PARTCNT covers
# all of file
for n in `seq 0 $PARTCNT`
do
dd if=file.gz of=part.$n bs=$CHUNKSIZE skip=$n count=1
done
此变体省略创建单个存档文件并直接创建部分:
gzip -c file.orig |
( CHUNKSIZE=1073741824;
i=0;
while true; do
i=$[i+1];
head -c "$CHUNKSIZE" > "part.$i";
[ "$CHUNKSIZE" -eq $(stat -c%s "part.$i") ] || break;
done; )
Tested code, initially creates a single archive file, then splits it:
gzip -c file.orig > file.gz
CHUNKSIZE=1073741824
PARTCNT=$[$(stat -c%s file.gz) / $CHUNKSIZE]
# the remainder is taken care of, for example for
# 1 GiB + 1 bytes PARTCNT is 1 and seq 0 $PARTCNT covers
# all of file
for n in `seq 0 $PARTCNT`
do
dd if=file.gz of=part.$n bs=$CHUNKSIZE skip=$n count=1
done
This variant omits creating a single archive file and goes straight to creating parts:
gzip -c file.orig |
( CHUNKSIZE=1073741824;
i=0;
while true; do
i=$[i+1];
head -c "$CHUNKSIZE" > "part.$i";
[ "$CHUNKSIZE" -eq $(stat -c%s "part.$i") ] || break;
done; )
In this variant, if the archive's file size is divisible by $CHUNKSIZE, then the last partial file will have file size 0 bytes.
发布评论
评论(4)
您可以使用
split
-b 选项的 a> 命令:可以使用 约书亚的回答。
正如 @Charlie 在下面的评论中所述,您可能想要显式设置一个前缀,因为否则它将使用
x
,这可能会令人困惑。最有效的解决方案与此答案的内容非常接近:
此解决方案避免了在压缩(解)压缩时需要使用中间大文件。 使用 tar -C 选项为生成的文件使用不同的目录。 顺便说一句,如果存档仅由单个文件组成,则可以避免 tar 并仅使用 gzip:
对于 Windows,您可以下载相同命令的移植版本或使用 Cygwin。
You can use the
split
command with the-b
option:It can be reassembled on a Windows machine using Joshua's answer.
As @Charlie stated in the comment below, you might want to set a prefix explicitly because it will use
x
otherwise, which can be confusing.The most effective solution is very close to the content of this answer:
This solution avoids the need to use an intermediate large file when (de)compressing. Use the tar -C option to use a different directory for the resulting files. btw if the archive consists from only a single file, tar could be avoided and only gzip used:
For Windows you can download ported versions of the same commands or use Cygwin.
如果您从 Linux 中分离出来,您仍然可以在 Windows 中重新组合。
If you are splitting from Linux, you can still reassemble in Windows.
使用 tar 到 分割成多个档案。
有很多程序可以在 Windows 上处理 tar 文件,包括 Cygwin。
Use tar to split into multiple archives.
There are plenty of programs that will work with tar files on Windows, including Cygwin.
测试的代码,最初创建一个存档文件,然后分割它:
此变体省略创建单个存档文件并直接创建部分:
在此变体中,如果存档的文件大小可以被
$CHUNKSIZE
整除,那么最后一个部分文件的文件大小将为 0 字节。Tested code, initially creates a single archive file, then splits it:
This variant omits creating a single archive file and goes straight to creating parts:
In this variant, if the archive's file size is divisible by
$CHUNKSIZE
, then the last partial file will have file size 0 bytes.