A
A
Alexey Kuznetsov2014-03-28 21:21:26
linux
Alexey Kuznetsov, 2014-03-28 21:21:26

How to extract a separate subfolder from an archive without saving the full path to it?

Let's say there is an archive with the following content:
arc.tar.gz
--one
----two
------someFile.txt
You need to extract the two folder to the current directory.
I try this:
tar -xzvf arc.tar.gz one/two
Result - the folder is extracted but with the preservation of the directory structure, that is, one / two.
How can I extract just folder two?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
@
@ntkt, 2014-03-29
@Webtoucher

GNU tar has a --strip=N magic option that strips N directory levels from the path root:
https://superuser.com/a/377247
https://www.gnu.org/software/tar/manual/tar. html#SEC114
And there is also a magic --xform option that allows you to rewrite paths with regexp!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question