Extract a specific folder to specific directory from a tar.gz Extract a specific folder to specific directory from a tar.gz linux linux

Extract a specific folder to specific directory from a tar.gz


Ok I figured it out!

Basically I can just use the strip command to remove the x number of leading directories. In this case, my command would look like this:

tar -xzf backup.tar.gz --strip-components=3 -C a/b/m

That removed the first three path directories from my archive (backup.tar.gz : a/b/c/d) before extracting it to the desctination directory.

Now it looks like this: a/b/m+d


This worked for me on OS X (pulling specific files from a GitHub repo):

# Move to target directory and run:curl -#L https://github.com/USER/REPO/tarball/BRANCH | tar -xzv --strip-components 3 --include=*./some/folder