0

I was working with a data.tar.bz2, which contains lots of other big files of the scale of a few hundred Gigabytes. I just wanted to see the header (first line) of a particular file file-of-interest, to see what is the header of file-of-interest.

Until now, I have just found how to list the files of tar.bz2 but no way of cat the contents of file-of-interest contained in the archive. Is there an efficient way to do so without uncompressing/extracting considering files contained are too big?

2

You cannot do anything without uncompressing (at least partially) the archive. However, you can extract only the file you're interested in directly to stdout. Example:

tar -xOf data.tar.bz2 file-of-interest | head -n1 
  • Works great. This is what I needed. – Sumit Sidana Sep 24 '18 at 17:24
  • If the file is toward start of archive, then the un-compression may stop early. – ctrl-alt-delor Sep 24 '18 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.