tar xvf to a different directory?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers tar xvf to a different directory?
# 1  
Old 03-23-2010
tar xvf to a different directory?

Hi all,

I have a tar file that was done with tar -cvf <tar_file> /directory.

Is there any way that I can untar this, i.e. tar -xvf <tar_file> into a different directory?

So far Google said you can't do tar -xvf to a different directory.

Unfortunately, am not the one doing the tar -cvf and I cannot convince the third-party to change their scripts as this is the syntax in all of their scripts.

Any advise of any workaround will be very much appreciated. Thanks in advance.
# 2  
Old 03-23-2010
Maybe you are looking for this?

Code:
tar cvf - cur_directory  | (cd newdirectory &&  tar xvf -)

# 3  
Old 03-23-2010
Bad news...
The standard behaviour of tar, if not given a relative path when creating an archive (that is ./ ) will always use an absolute path. But I never tried to see what happens with a chroot... (man chroot ! )
# 4  
Old 03-23-2010
chroot will do it but requires some configuration to work. Alternatively, you might use gnu tar which removes the leading slash by default, unless the -P option is given.

If Gnu tar isn't installed, you can still use pax which handles tar files and has an option to replace on the fly the path of extracted files. (eg: pax -s /directory/newdirectory/ ... ).
# 5  
Old 03-24-2010
I think you have justifiable cause to ask the third party to use relative paths when creating an archive with "tar".

jlliagre's idea of using "pax" is good. It has saved me much time before.

What Operating System and version are you using to read the "tar" archives. Do you have pax"?

As I am sure you know, "tar -tvf" will list the filenames on the archive enabling you to check whether you have a clash with your system. We don't know the structure of your filesystems in relation to the directory structure of the "tar" archive or whether this involves active files or programs.

Personally if I had to deal with unsolicited "tar" archives I would use an intermediate computer to inpect, expand (with "pax" to a controlled filesystem), check for viruses, perform basic data validation, and then transfer to the main computer for processing.
# 6  
Old 03-24-2010
Quote:
Originally Posted by dennis.jacob
Maybe you are looking for this?

Code:
tar cvf - cur_directory  | (cd newdirectory &&  tar xvf -)

Hi Dennis,

Unfortunately, am tarring xvf from a file

---------- Post updated at 07:12 PM ---------- Previous update was at 07:09 PM ----------

Quote:
Originally Posted by methyl
I think you have justifiable cause to ask the third party to use relative paths when creating an archive with "tar".

jlliagre's idea of using "pax" is good. It has saved me much time before.

What Operating System and version are you using to read the "tar" archives. Do you have pax"?

As I am sure you know, "tar -tvf" will list the filenames on the archive enabling you to check whether you have a clash with your system. We don't know the structure of your filesystems in relation to the directory structure of the "tar" archive or whether this involves active files or programs.

Personally if I had to deal with unsolicited "tar" archives I would use an intermediate computer to inpect, expand (with "pax" to a controlled filesystem), check for viruses, perform basic data validation, and then transfer to the main computer for processing.

Hi metyhl,

Am on AIX, did a which and there is /usr/bin/pax

I'll check on the man pages and see how it works, never used it before. As per jlliagre's post, I can use pax to extract from tar files as well, is that correct?
# 7  
Old 03-24-2010
Yes, pax can extracts tar files. It uses that file format by default actually.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Making Tar of directory and tar file is going to be placed

Quick question, is it possible to make a Tar of completely directory and placing the tar file in it (will this cause even the tar file to tarred ?) sample: /opt/freeware/bin/tar -cvf - /oracle | gzip > /oracle/backup.tgz will the tar file backup.tgz also include backup.tgz ? i tried... (5 Replies)
Discussion started by: filosophizer
5 Replies

2. Solaris

ZCAT xxx.Z|tar -xvf - decompression slow ?

I have recently built a new server and patched Soalris 10 up tp latest bundle etc... When I run a decompress using the format zcat fred.Z |tar -xvf - it runs at a very slow rate. A similiar server which is less powerful runs over twice as quick. Is there any work arounds to configure decompress... (4 Replies)
Discussion started by: smcart
4 Replies

3. UNIX for Advanced & Expert Users

Tar xvf in file

Good afternoom, I have a file very big, when I execute tar xvf XXXXXX_2010.tar, and show me this in the screen. x XXXXXX_2010_(01_DE_18).ixf, 3330845041 bytes, 6505557 media blocks. x XXXXXX_2010_(02_DE_18).ixf, 3336071703 bytes, 6515766 media blocks. x XXXXXX_2010_(03_DE_18).ixf, 3333011013... (3 Replies)
Discussion started by: systemoper
3 Replies

4. UNIX for Advanced & Expert Users

How to rsync or tar directory trees, with hidden directory, but without files?

I want to backup all the directory tress, including hidden directories, without copying any files. find . -type d gives the perfect list. When I tried tar, it won't work for me because it tars all the files. find . -type d | xargs tar -cvf a.tar So i tried rsync. On my own test box, the... (4 Replies)
Discussion started by: fld2007
4 Replies

5. Shell Programming and Scripting

tar command dont tar to original directory

HI, if I have a tarfile called pmapdata.tar that contains tar -tvf pmapdata.tar -rw-r--r-- 0/0 21 Oct 15 11:00 2009 /var/tmp/pmapdata/pmap4628.txt -rw-r--r-- 0/0 21 Oct 14 20:00 2009 /var/tmp/pmapdata/pmap23752.txt -rw-r--r-- 0/0 1625 Oct 13 20:00 2009... (1 Reply)
Discussion started by: borderblaster
1 Replies

6. Shell Programming and Scripting

I look help in tar xvf

Dears, I have copied one compressed file from one directory to another directory say finame.txt.tar.gz copied from FirstDirectory to SecondDirecory cd FirstDirectory / cp finame.txt.tar.gz SecondDirecory cd SecondDirecory/ once i do gunzip to finame.txt.tar.gz it, the file got... (4 Replies)
Discussion started by: faiz
4 Replies

7. AIX

tar -xvf doesnt work

Hello Im trying to extract this file tar -xvf opt-samba-base.tar.tar tar: 0511-169 A directory checksum error on media; 0 not equal to 75420. but I get that message I tried algo with gunzip and uncompress but nothing happens gunzip -d opt-samba-base.tar.tar gunzip:... (2 Replies)
Discussion started by: lo-lp-kl
2 Replies

8. Solaris

tar -xvf is showing error

Hi, When i am trying to untar a file for installation its showing an error like tar -xvf te_agent__sparc.en_tar.gz tar: directory checksum error Please help me to solve this issue........... (10 Replies)
Discussion started by: Renjesh
10 Replies

9. UNIX for Advanced & Expert Users

'tar -xvf' command filled up /dev/root

On a newly configured hp unix server, I got the following error while I was trying to untar a file: tar -xvf 9201rdbms.tar .... /htc_ora_prod/stage9.2.0_64bit/Disk2/stage/Components/oracle.rdbms.seeddb.compoltp/9.2.0.1.0/1/DataFiles/Expanded/seed/templates/Transaction_Processing.dfj, 174282115... (2 Replies)
Discussion started by: YuChing
2 Replies
Login or Register to Ask a Question