tar extract to different directory | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

tar extract to different directory

UNIX for Advanced & Expert Users


Tags
tar extract, tar extract directory, tar extract to directory

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-25-2007
ammu ammu is offline
Registered User
 
Join Date: Jul 2006
Last Activity: 26 August 2010, 9:37 AM EDT
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
tar extract to different directory

Hi,

I created a tar file of a directory dir1 from /tmp in the following way

$pwd
/tmp
$tar -cvf dir1.tar dir1 (dir1 will have say file1)

Now i want to extract it in the directory /tmp/dir2 so that the directory dir1 is also created and extracted (/tmp/dir2/dir1/file1). Is there any way without creating the directory first(dir1) the dir1 can be extracted?

Thanks in advance
Ammu
Sponsored Links
    #2  
Old 07-25-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 22 December 2014, 6:30 PM EST
Location: Foxborough, MA
Posts: 7,679
Thanks: 156
Thanked 591 Times in 555 Posts

Code:
(cd /tmp; tar cf - dir1) | (cd /tmp/dir2; tar xf - )

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Loop through directory and extract sub directory names personalt UNIX for Dummies Questions & Answers 1 08-29-2011 01:13 PM
How to extract contents of ONLY one directory from ZIP folder. Sheel UNIX for Dummies Questions & Answers 2 03-04-2011 08:24 AM
Extract directory from a file path mrudula009 Shell Programming and Scripting 4 06-10-2009 02:48 AM
How to extract archive to a specified directory john_trinh UNIX for Dummies Questions & Answers 4 03-02-2004 06:07 PM
redirecting tar extract to another directory colesy UNIX for Dummies Questions & Answers 7 01-28-2003 04:40 AM



All times are GMT -4. The time now is 09:32 PM.