AIX 5.3 Tar - Exctact to a different directory

1

I am trying to extract a untar a file to a different directory on a AIX 5.3 box

tar -xvf -C /tmp/ ./MyFile.tar 
tar: -C: No such file or directory

tar -C /tmp -xvf ./MyFile.tar
Usage: tar {c|r|t|u|x} [ bBdDEfFhilLXmNopRsSUvw[0-9] ]

tar -xvf ./MyFile.tar -C /tmp/
tar: file -C: not present in archive
tar: file /tmp/: not present in archive

Note:

  • Installing GNU tar is not an option

  • I would prefer not to CD to the target dir first

  • I have seen this answer on SU

Thanks

eramm

Posted 2015-04-20T15:29:33.963

Reputation: 113

Answers

2

The -C option only applies when you create an archive, not when you restore it. Your only option is to cd into the directory to restore into first, like this:

( cd /tmp && tar -xvf /<pathToMyFile.tar>/MyFile.tar )

pichogve

Posted 2015-04-20T15:29:33.963

Reputation: 36

0

I had the same problem with tar, so I used pax:

pax -rf <tarfile> -s/regexToInitialTargetDir/regexToFinalTargetDir/p

In my case this was the target was /volume01/sotcha/ and I wanted to extract to /home/sotcha/ so the regex part was

-s/volume01/home/p

sotcha

Posted 2015-04-20T15:29:33.963

Reputation: 101