简体   繁体   中英

Split tar.bz2 file and extract each individually

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

Thanks,

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.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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