cancel
Showing results for 
Search instead for 
Did you mean: 

tar -xf in new directory

JianW
Occasional Advisor

tar -xf in new directory

Hi, all
Having problems tar -x archive in new directory.

I created tar file like this:
cd /source/out
tar -cvf bills.tar gm_*.zip

then copied it to new /gm/webserver dir and tried to exract all files being there, and I just realized that it remember it old source/out directory. Nothing extracted.
Tried this:
tar -C /gm/webserver/ -xvvf bills.tar

and still verbose output shows that it points to old /source/out/gm_01.zip path.
and nothing was extracted to /gm/webserver/.

What is the trick here, do I need to use any special option while creating tar -cf ?

Tx to all
Jian

3 REPLIES
Steven Schweda
Honored Contributor

Re: tar -xf in new directory

> I just realized that it remember it old
> source/out directory. [...]

It did? I don't see why it would, _if_ you
created the "tar" archive the way you said
that you did.

tar tfv bills.tar

> What is the trick here, [...]

It should work as desired if you specify a
relative path, not an absolute path, when
you create the archive.

Relative (often good):
cd /source/out
tar cf /bills.tar gm_*.zip

Absolute (often bad):
tar cf /bills.tar /source/out/gm_*.zip

GNU "tar" also offers some options which
allow the user to modify/transform the paths
when files are extracted.

http://www.gnu.org/software/tar/manual/
http://www.gnu.org/software/tar/manual/html_node/transform.html#SEC108
Dennis Handly
Acclaimed Contributor

Re: tar -xf in new directory

>Tried this: tar -C /gm/webserver/ -xvf bills.tar

-C is what you use when creating the tarfile.

>do I need to use any special option while creating tar -cf

You either need to be in that directory as Steven said, or you can use -C:
tar -cvf bills.tar -C /source/out .
(Note: that "*" won't work because you aren't in that directory yet.)
Sp4admin
Trusted Contributor

Re: tar -xf in new directory

This is from the man page.

Archive all files and directories in directory my_project in the
current directory to a file called my_project.TAR, also in the current
directory:

tar -cvf my_project.TAR my_project

sp,