1

I am aware that you can extract a single file from tar.

tar -xf file.tar.gz /small/single/file

I intend to run this on an embedded system with limited disk/ram. I'd like to know how this command handles large tarballs.

Does extracting a single file cause the entire tarball to be decompressed into memory? I don't mind decompressing it all, but as long it does so with a small buffer.

Let's say I have 100MB of RAM avaible and 5MB of disk space available. Also, /small/single/file is under 5MB. Also, the source tarball is 500MB. Can I safely extract /small/single/file?

2 Answers 2

1

The answer probably depends on the implementation of tar you’re using, but realistically, I’d expect most implementations to process the tarball using a relatively small buffer. Using GNU tar on a 2GiB bzip2-compressed tarball, to extract a single file, I get

64.07user 4.84system 2:53.45elapsed 97%CPU (0avgtext+0avgdata 4664maxresident)k
4046976inputs+8outputs (0major+1194minor)pagefaults 0swaps

(using GNU time). As you can see, the maximum resident size is under 5MiB.

0

To minimize the RAM/disk usage I would recommend to use pipes like this:

gzip -dc file.tar.gz| tar -f - /small/single/file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .