linuxunixziptarbzip

Unzip a single file in a tbz archive


I have the following archived directory:

itunes20140618.tbz

I want to extract single file from it called:

itunes20140618/video

How would I do this?

So far, I am doing

$ bzip2 -d /tmp/itunes20140618.tbz 

But it seems to create a tar directory of everything. How would I extract just the single video file?


Solution

  • There are a few different versions of tar around, but on my machine I can do this:

    tar xjf archive.tbz filename
    

    To extract filename from archive.

    If that doesn't work you can use:

    bzip2 -dc archive.tbz | tar xvf - filename
    

    Which uses bzip2 to extract to stdout and then pipe to tar.

    In both cases you can replace the x option with t to get a list of files. Eg:

    tar tjf archive.tbz