1

I have a couple tarballs that are many gigabytes large and contain several thousand files and am wondering if it is possible to convert these to more versatile 7z archives, because the current tarballs make pulling individual files out of them very tedious. If at all possible I would like to do this in-place, i.e. without having to fully extract the tarballs.

I thought I could do it with the following command, but the resulting archive just contains a single file with all the data.

tar -xf 100GB.tar -O | 7za a -si -ms=16f32m 100GB.7z

Is this somehow possible?

  • 1
    by the way, uncompressed tar archives make no sense for archival – the same files lying around in folders would use (if any) little more space, and would solve your access problem alltogether. – Marcus Müller Feb 01 '23 at 17:16
  • and for archives of file systems, 7z is not suitable: unlike 7z, is has no proper notion of file ownership, permissions, and other metadata. See also my answer here: https://unix.stackexchange.com/questions/731609/difference-between-ar-tar-gzip-zip-and-when-should-i-decide-to-choose-which-o/731610#731610 – Marcus Müller Feb 01 '23 at 17:19
  • If you compress your tar archive with pixz, beside getting better compression than 7zip, you can do random access to individual files. – Stéphane Chazelas Feb 01 '23 at 19:39

1 Answers1

1

archivemount allows you to mount tar archives without extracting them. You can then just compress the contained files as if they were laying around anywhere else. I've not used it many times. And I think its website went down quite a while ago, maybe not the best sign.

If you're not set on 7z but could use a similarly well-compressing tool, which on top of all also allows you to generate archives that retain all permissions, can be mounted by any modern Linux out of the box (i.e. without installing third-party userland filesystems like archivemount):

mksquashfs my_new_compressed_archive.squash  -comp zstd  -tar        < 100GB.tar
#          | target archive name          | |compressor| |read tar|  |read from this file|
#                                           |          \______
#                                           |use -comp lzma   |
#                                           |to use the same  |
#                                           |compressor as 7z.|
#                                           |Usually, zstd is |
#                                           |a good choice, as|
#                                           |it's not as slow |
#                                           |as LZMA/7z at    |
#                                           |reasonable com-  |
#                                           |pression ratios. |
#                                           |Also, unlike LZMA|
#                                           |zstd-compressed  |
#                                           |squashfs can be  |
#                                           |mounted by the   |
#                                           |Linux kernel.    |
#                                           \~~~~~~~~~~~~~~~~~/

You can then mount your freshly created archive even as normal user:

udiskctl loop-setup -f my_new_compressed_archive.squash