tar -tf filename.tar
folder1/file
folder1/name
[...]

I'd like to extract file and name to, folder2. Can this be done as a one-liner?

link|improve this question

73% accept rate
feedback

2 Answers

up vote 6 down vote accepted

Use -C and --strip-components (See man tar).

link|improve this answer
I read man tar. Didn't spot --strip-components. nice one – Felipe Alvarez May 30 '10 at 6:25
tar-1.14 uses --strip-path, tar-1.14.90+ uses --strip-components. Maybe problem here? – mmv-ru Jun 26 '11 at 7:42
feedback

You can also use the --transform option for a bit more flexibility. It accepts any sed replacement (s) operation.

For example, this is how I extract a Linux tarball to a new directory so I can apply a patch:

tar -xjf linux-2.6.38.tar.bz2 --transform 's/linux-2.6.38/linux-2.6.38.1/'
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.