LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-26-2006, 06:40 AM   #1
hcclnoodles
Member
 
Registered: Apr 2003
Posts: 50

Rep: Reputation: 15
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
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 10-26-2006, 08:16 AM   #2
Wells
Member
 
Registered: Nov 2004
Location: Florida, USA
Distribution: Debian, Redhat
Posts: 417

Rep: Reputation: 53
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.
 
Old 10-28-2006, 12:40 AM   #3
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
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
 
5 members found this post helpful.
Old 05-19-2009, 07:31 AM   #4
nikwax
LQ Newbie
 
Registered: May 2009
Posts: 25

Rep: Reputation: 0
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 -
 
Old 03-05-2011, 03:47 PM   #5
awalrath
LQ Newbie
 
Registered: Mar 2011
Posts: 1

Rep: Reputation: 0
Cool

Quote:
Originally Posted by Berhanie View Post
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!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How To extract .tar.gz To A Specific Directory? George2 Linux - Software 4 02-18-2006 07:01 AM
how to extract mutiple tar.gz int21h Linux - Newbie 14 12-08-2005 06:58 AM
tar extract fails dgermann Linux - Newbie 8 08-28-2004 11:26 AM
Choosing where to extract tar.gz Arclite Linux - Software 14 08-14-2003 03:57 PM
extract error tar.gz eye Linux - Software 6 05-18-2003 12:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration