Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-26-2006, 07:40 AM   #1
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

Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 10-26-2006, 09:16 AM   #2
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, 01:40 AM   #3
Senior Member
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
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 ???
tar xvf /data/package.tar -C /usr
5 members found this post helpful.
Old 05-19-2009, 08:31 AM   #4
LQ Newbie
Registered: May 2009
Posts: 25

Rep: Reputation: 0
extract tar file to a different folder

I tried this:
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:
cd /path/to/where/files/are/required
cat /path/to/file.tar | tar xf -
Old 03-05-2011, 04:47 PM   #5
LQ Newbie
Registered: Mar 2011
Posts: 1

Rep: Reputation: 0

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:01 AM
how to extract mutiple tar.gz int21h Linux - Newbie 14 12-08-2005 07:58 AM
tar extract fails dgermann Linux - Newbie 8 08-28-2004 12:26 PM
Choosing where to extract tar.gz Arclite Linux - Software 14 08-14-2003 04:57 PM
extract error tar.gz eye Linux - Software 6 05-18-2003 01:00 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:48 PM.

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