4

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?

Currently, if I extract one file via tar it takes about 1 minutes and then 'hangs' for another 20 minutes while it finishes reading the tar archive. Any ideas how to improve this?

7
tar -xvjf itunes20140618.tbz itunes20140618/video

That should do it for this case, but if you need more help do:

info tar

To extract specific archive members, give their exact member names as arguments, as printed by --list (-t). If you had mistakenly deleted one of the files you had placed in the archive collection.tar earlier (say, blues), you can extract it from the archive without changing the archive's structure. Its contents will be identical to the original file blues that you deleted.

First, make sure you are in the practice directory, and list the files in the directory. Now, delete the file, blues, and list the files in the directory again.

You can now extract the member blues from the archive file `collection.tar' like this:

 $ tar --extract --file=collection.tar blues

If you list the files in the directory again, you will see that the file blues has been restored, with its original permissions, data modification times, and owner. (These parameters will be identical to those which the file had when you originally placed it in the archive; any changes you may have made before deleting the file from the file system, however, will _not_ have been made to the archive member.) The archive file, collection.tar, is the same as it was before you extracted blues. You can confirm this by running tar with --list (-t).

1

An archive like a .zip, .rar or .7z consists of many files bundles together and compressed. A .tar archive consists of many files bundled together, but the tar format does not include any compression. A .gz, .bz2 or .xz file is a single compressed file. A .tar.gz, .tar.bz2, etc. is a compressed archive; .tbz is a suffix that is occasionally used instead of .tar.bz2, just like how .tgz is sometimes used instead of .tar.gz.

bzip2 -d /tmp/itunes20140618.tbz uncompresses the file. You're left with the uncompressed tar archive. bzip2 doesn't create a tar: it decompresses what is given to it, and since it is given a compressed tar, the output is an uncompressed tar. You can untar the resulting file with tar -xf /tmp/itunes20140618.tar. To extract just one file, that's tar -xf /tmp/itunes20140618.tar itunes20140618/video.

Reasonably recent versions of tar on Linux, FreeBSD, MINIX3 and OSX automatically detect compressed archives, so you can call tar in the first place without worrying about the compression used on the archive:

tar xf itunes20140618.tbz itunes20140618/video

Older versions of tar, as well as many systems today such as OpenBSD, Solaris and Linux with BusyBox, can at least call bzip2 under the hood even if you have to tell them explicitly with the -j option.

tar -xjf itunes20140618.tbz itunes20140618/video

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.