使用 tar、gz、zip 或 bzip2 拆分文件

发布于 2024-07-26 19:03:05 字数 1460 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夏日落 2024-08-02 19:03:05

您可以使用 split-b 选项的 a> 命令:

split -b 1024m file.tar.gz

可以使用 约书亚的回答

copy /b file1 + file2 + file3 + file4 filetogether

正如 @Charlie 在下面的评论中所述,您可能想要显式设置一个前缀,因为否则它将使用 x ,这可能会令人困惑。

split -b 1024m "file.tar.gz" "file.tar.gz.part-"

// Creates files: file.tar.gz.part-aa, file.tar.gz.part-ab, file.tar.gz.part-ac, ...

最有效的解决方案与此答案的内容非常接近:

# 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

此解决方案避免了在压缩(解)压缩时需要使用中间大文件。 使用 tar -C 选项为生成的文件使用不同的目录。 顺便说一句,如果存档仅由单个文件组成,则可以避免 tar 并仅使用 gzip:

# Create archives
gzip -c my_large_file | split -b 1024MiB - myfile_split.gz_

# Uncompress
cat myfile_split.gz_* | gunzip -c > my_large_file

对于 Windows,您可以下载相同命令的移植版本或使用 Cygwin。

You can use the split command with the -b option:

split -b 1024m file.tar.gz

It can be reassembled on a Windows machine using Joshua's answer.

copy /b file1 + file2 + file3 + file4 filetogether

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.

split -b 1024m "file.tar.gz" "file.tar.gz.part-"

// Creates files: file.tar.gz.part-aa, file.tar.gz.part-ab, file.tar.gz.part-ac, ...

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:

# Create archives
gzip -c my_large_file | split -b 1024MiB - myfile_split.gz_

# Uncompress
cat myfile_split.gz_* | gunzip -c > my_large_file

For Windows you can download ported versions of the same commands or use Cygwin.

昔梦 2024-08-02 19:03:05

如果您从 Linux 中分离出来,您仍然可以在 Windows 中重新组合。

copy /b file1 + file2 + file3 + file4 filetogether

If you are splitting from Linux, you can still reassemble in Windows.

copy /b file1 + file2 + file3 + file4 filetogether
孤芳又自赏 2024-08-02 19:03:05

使用 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.

坦然微笑 2024-08-02 19:03:05

测试的代码,最初创建一个存档文件,然后分割它:

 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; )

在此变体中,如果存档的文件大小可以被 $CHUNKSIZE 整除,那么最后一个部分文件的文件大小将为 0 字节。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文