LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tar - extract to different directory (https://www.linuxquestions.org/questions/linux-newbie-8/tar-extract-to-different-directory-495715/)

hcclnoodles 10-26-2006 06:40 AM

tar - extract to different directory
 
Hi there, if i am in /opt and i want to extract /data/package.tar to /usr, how do I do it...How can I extract to a directoory that im not currently in ???

eg ....(I thought this would work but it doesnt)

#cd /opt
# tar xvf /data/package.tar /usr

cheers

Wells 10-26-2006 08:16 AM

Reading through the man page for tar, I don't think you can do this. If you want to extract the files from a tarfile "foo.tar", you would simply go to the directory that you want to use as a starting point and then extract it from there. For instance, if I have a tarfile named "foo.tar" in my home directory "/home/bar", and I want to extract that tar file into /opt, I would do the following:

# cd /opt
# tar xvf /home/bar/foo.tar

When you tried to do "tar xvf /data/package.tar /usr", as far as tar was concerned what you were asking to do was extract the file "/usr" from the tarfile package.tar. This may or may not have worked, depending on what was actually in the package.tar file. :)

Berhanie 10-28-2006 12:40 AM

Quote:

i am in /opt and i want to extract /data/package.tar to /usr, how do I do it...How can I extract to a directoory that im not currently in ???
Code:

tar xvf /data/package.tar -C /usr

nikwax 05-19-2009 07:31 AM

extract tar file to a different folder
 
I tried this:
Code:

tar xvf /data/package.tar -C /usr
but it didn't work for me, I got an error about being unable to execute a remote shell.

This did work though, and might be more portable:
Code:

cd /path/to/where/files/are/required
cat /path/to/file.tar | tar xf -


awalrath 03-05-2011 03:47 PM

Quote:

Originally Posted by Berhanie (Post 2480390)
Code:

tar xvf /data/package.tar -C /usr

Thanks, the -C modifier worked perfectly to extract files to a different directory other than the current one!


All times are GMT -5. The time now is 11:53 AM.