Untar specific directory and strip leading directories

Ok so I know the title was probably confusing so here goes: I have a tarball (gzipped) that has a nested directory structure . For example:

 my.tar.gz (contents)
           [.]
             ---[var]
             ---[var]---[foo]
             ---[var]---[foo]---[bar]
             ---[var]---[foo]---[bar]---[dir]
             ---[var]---[foo]---[bar]---[dir]---[thats]
             ---[var]---[foo]---[bar]---[dir]---[thats]---[nested]

What I'm having the hardest time doing is extracting the directory [dir]--[thats]---[nested] ONLY. So no /var/foo/bar before it, just that directory and it's subdirectories. Real world dir/thats/nested/ is about 6 levels down. I'm restoring from the tarball and /dir/thats/nested is the actual directory on my box. So when i extract from it, i want it to overwrite /dir/thats/nested ON MY BOX. Kinda frustrated...I'll accept any good working solution for this at this point. Basically trying to not have to copy the tarball to the / directory to get it to overwrite /dir/thats/nested.

If you have gnu tar you can use --strip=3 to remove the /var/foo/bar.

Good to also use --show-transformed if you're using the -v option to list what's being extracted.

1 Like

There's a reason you're listed in the credits of my script lol