Split tar.bz2 file and extract each individually

谁都会走 提交于 2019-12-12 17:15:33

问题


Can I split a large tar.bz2 file into several smaller files and extract those small tar.bz2 files individually in Ubuntu?

Thanks,


回答1:


I don't think it's easily possible. A .tar.bz2 is a single stream, it doesn't have an index like zip that would allow skipping to the start of a particular file within the archive. You can split the file using split utility, and than cat the parts and extract them (you can do this via stdin to avoid re-creating the pasted file on disk). The first fragment will be possible to extract separately (except for the last file in it which will probably be damaged), but further fragments will not be usable without the onces that come before them.




回答2:


You could try the --multi-volume option:

tar -cf archive.tar --multi-volume --tape-length 1024 folder

Unfortunately, it does not work with compressed archives:

tar: Cannot use multi-volume compressed archives

You could compress volumes individually, but the size of the volumes might vary considerably.

Hope it solves your use-case.




回答3:


Not sure if help is still needed on this, but I have found a method that will at least allow you to use the split command along with tar (bz2) compression. As far as extracting each file individually, this option sees the files as a part of a whole (much like Winzip does when spanning multiple volumes...if one of the volumes is missing, the archive as a whole is corrupt). With that said:

Creating split files. Note that this will create files sequentially with "aa, ab, ac" designations:

tar -cv(z/j)f - (files to be archived) | split -b(size in bytes, such as 4000m) - (name for output archive file)

Extracting split files:

cat (file*) | bzcat/gunzip(-d) | tar (t/x)v(j/z)f -

(If you used the "j" option, bzcat would go inside the pipes) or (If you used the "z" option, gunzip would go inside the pipes). You may also need to use "gunzip -d" within these two pipes if you get an error




回答4:


TO split the file into multiple files.

It will automatically create files of size 1.1GB, if your tar is bigger in size, you can increase the number, for an example 1000 {2..1000} or you can increase the input to tape-length argument.

tar --tape-length=1048576 -cMv --file=tar_archive.{tar,tar-{2..100}} backup.tar.lzma

but as @michal said, it is not possible to extract them individually.

tar: backup.tar.lzma: Cannot extract -- file is continued from another volume
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now


来源:https://stackoverflow.com/questions/10282296/split-tar-bz2-file-and-extract-each-individually

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!