HOW TO extract.tar file to specific directory..?

Hi all,

In Solaris howto extract tar file to specific folder.

This is what we do in Linux, but how to do the same thing in Solaris ?

-tar     -xzvf   /tmp/etc.tar.bz  -C /tmp 

(Will extract in /tmp dir)

3.gzip COMPRESSION AND EXTRACTION
-tar     -czvf  /tmp/etc.tar.bz     /etc
-du           -csh   /tmp/etc.tar.bz   7.4M
-tar     -xzvf   /tmp/etc.tar.bz
-tar     -xzvf   /tmp/etc.tar.bz  -C /tmp 

(Will extract in /tmp dir)

Usually, the tar has a relative path, which you can see in the t output. It will make the leading directory if any. So, run tar in the target directory where you want that subtree:

( cd somewhere ; tar xf - ) < whatever.tar
1 Like

Lets say you want to tar testzone.tar in /zones directory

# mv testzone.tar /zones
# cd /zones 
verify that the file is in the /zones director
# ls
# tar xf testzone.tar
# ls
1 Like

Hi cjashu

What you say is right but, if I need to write in script extract in particular directory then your method wont work.

May be what DGPickett said would work...

Unix tar does not have a built-in (de)compression.
The advantage is that the newest (de)compression methods can be used without updating the tar binary.
The disadvantage is that you must get used to complex shell code.
Example:

bunzip2 -c whatever.tar.bz2 | ( cd somewhere && tar xvf - )

The && is safer than the semicolon.

Yes, more generally, just decompress stdin:

any_appropriate_decompress_tool <yours.some_comp_tar_ext | ( cd somewhere && tar xvf - )

gunzip or gzcat for .tgz, .tar.gz and .tar.Z,
uncompress for tar.Z,
bunzip2 for .tbz or .tar.bz2

Pipes are neat for moving stuff through rsh/ssh to another host without making a local copy of the compressed file.