Tar Command – How to Extract Specific Files from tar.gz

tar

How can we extract specific files from a large tar.gz file? I found the process of extracting files from a tar in this question but, when I tried the mentioned command there, I got the error:

$ tar --extract --file={test.tar.gz} {extract11}
tar: {test.tar.gz}: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

How do I then extract a file from tar.gz?

Best Answer

You can also use tar -zxvf <tar filename> <file you want to extract>

You must write the file name exacty as tar ztf test.tar.gz shows it. If it says e.g. ./extract11, or some/bunch/of/dirs/extract11, that's what you have to give (and the file will show up under exactly that name, needed directories are created automatically).

  • -x: instructs tar to extract files.
  • -f: specifies filename / tarball name.
  • -v: Verbose (show progress while extracting files).
  • -z: filter archive through gzip, use to decompress .gz files.
Related Question