Operating System - Linux
1748185 Members
4327 Online
108759 Solutions
New Discussion юеВ

Re: decompress to another directory

 
SOLVED
Go to solution
Tonatiuh
Super Advisor

decompress to another directory

Red Hat Linux 3 and 4.

Escenario:

1) I compress a directory into a tar file:

$ tar -zcvf MyTar.tar.gz /oback/*

2) I want to decompress the files to another directory. This is I want that my compressed (tar.gz) files be created into a different directory from the one that were taken. Something like...

$ tar -zxvf MyTar.tar.gz "to directory /NewDir/

10 REPLIES 10
Ivan Ferreira
Honored Contributor
Solution

Re: decompress to another directory

You should do this:

$ cd /oback
$ tar zcvf /path/to/mytar.tgz *

Then to restore

$ cd /NewDir
$ tar zxvf /path/to/mytar.tgz
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Steven E. Protter
Exalted Contributor

Re: decompress to another directory

Shalom,

-C

man tar

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Stuart Browne
Honored Contributor

Re: decompress to another directory

Just to expand on what Ivan said, you should get into the habbit of now using an absolute path with tar.

Some of the older tar versions, and some of the non-GNU tar's, wont strip the absolute-path's leading /..
One long-haired git at your service...
Tonatiuh
Super Advisor

Re: decompress to another directory

Maybe I have explained wrong.

The original path of the files is:

/orafiles/pruebas/01/*

But I want to decompress them to:

/oback/xyz/*

The "-C" option, decompress them to:

/oback/xyz/orafiles/pruebas/01/*

I wanti to remove the original path "/orafiles/pruebas/01/" and decompres (create) the files DIRECTLY in "/oback/xyz"

Is that possible?

If not, I need to decompress (with all the original path and then move them to the new path, but this is a task consuming time.

Stuart Browne
Honored Contributor

Re: decompress to another directory

Nope.. Multiple steps..

Asumming there are multiple things in 'oback', you can do only a partial restore (it'll take about the same time though).

Once it's restored though, the 'mv' command to put it in the right place should be near-instantaneous (same filesystem move only updates inode tree, doesn't actually move data).
One long-haired git at your service...
Manajit
New Member

Re: decompress to another directory

No tar can't do that.

Never use an absolute path, linux tar warns of this. The problem is that when you unpack, you will be forced to unpack to the same absolute path. While creating a tar file you should change to the appropriate directory and tar from there.

To remove directory name after tar, mv command would be better.
cd oback/xyz
mv orafiles/prubase/01/*.* .
Mike Stroyan
Honored Contributor

Re: decompress to another directory

The pax command will read tar format and has an option to do substitution of patterns in the names of files that it restores. Pax does not have an option to do gunzip decompression from a file, although it does have an option to do bzip2 decompression. Unpacking your example tar file into /oback/xyz/ will need a separate gunzip like this.

gunzip < MyTar.tar.gz | pax -rv -s ^/orafiles/pruebas/01/^/oback/xyz/^
Mike Stroyan
Honored Contributor

Re: decompress to another directory

If your tar creating operation did strip off the leading /, then you don't want that in the substitution pattern. You would use this command instead.

gunzip < MyTar.tar.gz | pax -rv -s ^orafiles/pruebas/01/^/oback/xyz/^
Tonatiuh
Super Advisor

Re: decompress to another directory

Stuart,

There is a very time consuming task to move the decompressed files if the movement is from one filesystem inside th local disk to another filesystem inside the NAS storage. The sum of all files is more than 50GB.

To change my default directory to the directory where are all the files to compress is a good (an already tested) opcion for me. But changing the pattern is also a good and more flexible solution.

Thanks to all for your knowledge and for your time.