[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Extracting indiviual files or directories from XYZ.tar.xz - Possible?



On 2025-08-09 12:39:35 -0700, Michael Paoli wrote:
> On Sat, Aug 9, 2025 at 2:50 AM Vincent Lefevre <vincent@vinc17.net> wrote:
> > On 2025-08-09 01:30:52 -0700, Michael Paoli wrote:
> > > < tar.xz | xz -d | tar tf -
> >
> > With tar utilities that support xz (like GNU tar), not using "xz -d"
> > could be more efficient as "xz -d" will uncompress the whole file
> > while this may not be necessary:
> >
> >   tar tf file.tar.xz
> >
> > is sufficient. This may allow one to skip xz blocks if the archive
> > contains big files. That said, I don't know whether GNU tar has
> > such an optimization.
> I rather doubt any tar implementation has such an optimization.
> I don't think there's any tar format that has an "index" or the like,

There is no need for an index (though an index would allow even
better optimization).

> it's generally just a tar header, then for each file (of any type),
> specific header for that, and any associated data, and I think there's
> also some type of end marker or the like, perhaps with a bit of metadata
> at the end too.

What's important is that there is a file size. For instance, "tar -t"
does not need to read the full contents of the archive: it can use
fseek to skip file contents (when the file is seekable).

In a compressed archive, you may have blocks that are entirely part of
a single file. In such a case, decompressing such blocks is useless if
the concerned file does not have to be extracted.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)


Reply to: