0

I have a .tar.gz as input and want to extract the first 128 MiB of it and output as a .tar.gz in a single command. I tried:

sudo tar xzOf input.tar.gz | sudo dd of=output bs=1M count=128 iflag=fullblock | sudo tar -cfz final.tar.gz -T -

which is obviously not working. How can I achieve this.

1
  • Why do you use sudo on second and third command? Try second tar to be tar czf.... Commented Jan 28, 2023 at 15:44

1 Answer 1

1

Instead of trying to extract the archive’s contents (which can’t work here — there’s no way to track the individual files’ metadata), decompress it, truncate it and recompress it. If you have a version of head capable of this:

gzip -dc input.tar.gz | head -c128M | gzip -c > final.tar.gz

or you can use dd as in your command:

gzip -dc input.tar.gz | dd bs=1M count=128 iflag=fullblock | gzip -c > final.tar.gz

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.