I have created a tar file in terminal. Let's say I am currently in a directory test7. I am creating a tar in my current directory of a file which is inside another directory (test8).
tar -czvf example.tgz ../test8/a/boutput:
example.tgzNow, I untar this file using the following command :
tar -xzvf example.tgzI get the result and a directory named as test8 is produced.
$) cd test8
$) ls
-> a
$) cd a
$) ls
-> bNow I can go inside the directory b and see my files.
I want the output to be only the directory a and inside of which b will be present i.e.
Output after untarring that I want should be of this hierarchy : a/bBut not: test8/a/b
Can anyone please help me out with this ? I have been through the man page of tar but couldn't get much help from it.
1 Answer
You can use the -C option to effectively change to the target directory
Ex. instead of
$ tar cvf example.tar ../Apple/Banana/Papaya
tar: Removing leading `../' from member names
../Apple/Banana/Papaya/
../Apple/Banana/Papaya/Papaya.mduse
$ tar cvf example.tar -C ../Apple Banana/Papaya
Banana/Papaya/
Banana/Papaya/Papaya.mdAlternatively you can remove leading directories upon extraction using the --strip-components option:
tar --strip-components=1 -xzvf example.tgz 3