Problem:
I have a tar file with a deep directory hierarchy but only some files in it. I want to extract the files into my current directory and not care for subdirectories. Filenames do not conflict. The gnu tar option --remove-components does not handle this well.Solution:
Fortunately, there is a very general gnu tar option --transform:tar --extract --transform='s/.*\///' --show-transformed-names --file=foo.tarThis deletes pathname up to the first slash character, resulting in the desired effect.
Example:
$ mkdir -p a/b/c/d/e/f/g/h/i $ echo "hi there" > a/b/c/d/e/f/g/h/i/foobar $ tar cvf foo.tar a a/ a/b/ a/b/c/ a/b/c/d/ a/b/c/d/e/ a/b/c/d/e/f/ a/b/c/d/e/f/g/ a/b/c/d/e/f/g/h/ a/b/c/d/e/f/g/h/i/ a/b/c/d/e/f/g/h/i/foobar $ tar --extract --transform='s/.*\///' --show-transformed-names --verbose --file=foo.tar a b c d e f g h i foobar $ cat foobar hi there
No comments:
Post a Comment