Q:

Untar a specifc folder within tar.gz

How do I untar/uncompress a specific folder within a tar.gz using the terminal/commandline (Ubuntu 14.04 (Trusty Tahr))?
Precise:
-file.tar.gz
 -- folder1
 -- folder2

How to extract...
... folder1 -->  ~/locationX
... folder2 --> ~/locationY

How can I do this?
Please notice:
This is purely related to terminal/commandline and not Puppet. This is just one example - I would save roughly 50 additional steps in Puppet, if there is a command to uncompress a specific folder from within a tar.gz as I could avoid moving files around...

A:

I think this should do it:
tar -xzf file.tar.gz -C ~/locationX folder1 -C ~/locationY folder2

The -C option means to change to the specified directory before doing the extraction. Specifying filename arguments after the tarfile name restricts the extraction to just those files or directories. And you can repeat this -Changing directories as you do.
Note that this will do the extractions in subdirectories:folder1 will go into ~/locationX/folder1, folder2 will go into ~/locationY/folder2. You can prevent this by using the --strip-components option:
tar -xzf file.tar.gz -C ~/locationX --strip-components=1 folder1 \
                     -C ~/locationY --strip-components=1 folder2

Also, if the actual prefixes in the tar file are ./folder1 and ./folder2, as is likely if you created the tar file with tar -czf file.tar.gz ., you'll need to include the ./ prefix in the filename arguments, and change to --strip-components=2.

