Unix/Linux Go Back    

AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.



aix, unix

Thread Tools Search this Thread Display Modes
Old Unix and Linux 12-02-2008
allwin allwin is offline
Registered User
Join Date: Dec 2008
Last Activity: 24 July 2012, 10:38 AM EDT
Posts: 11
Thanks: 4
Thanked 0 Times in 0 Posts


How can i untar a set of files in to different directory.

This is content

tar -tvf samba.tar
drwxrwxrwx 0 0 0 Nov 28 18:35:41 2008 samba/
-rw-r--r-- 0 0 0 Nov 18 15:12:40 2008 samba/b.txt
-rw-r--r-- 0 0 0 Nov 18 15:12:40 2008 samba/c.txt
-rw-r--r-- 0 0 0 Nov 18 15:12:40 2008 samba/d.txt
drwxrws--- 0 0 0 Nov 28 18:35:41 2008 samba/test/
-rw-r--r-- 0 0 0 Nov 18 15:12:40 2008 samba/a.txt

I need to extract the file without creating samba folder.

Is it possible?

Many thanks

Last edited by allwin; 12-02-2008 at 08:20 AM..
Sponsored Links
Old Unix and Linux 12-02-2008
zaxxon's Unix or Linux Image
zaxxon zaxxon is offline Forum Staff  
code tag tagger
Join Date: Sep 2007
Last Activity: 27 April 2017, 7:53 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,552
Thanks: 171
Thanked 553 Times in 476 Posts
Not that I know. Best you just tar it without leading samba or just extract it at some tmp directory and mv only the part to the destination that you need.
Sponsored Links
Old Unix and Linux 12-02-2008
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
Join Date: May 2005
Last Activity: 29 April 2017, 2:24 PM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 5,407
Thanks: 99
Thanked 1,491 Times in 1,108 Posts
You can limit what gets extracted from the archive by using a filename. For instance, going with your example, to extract only a.txt you could issue

tar -xvf samba.tar samba/a.txt

but this would still create a directory "./samba" and put "a.txt there. It would only prevent the other files getting untarred too.

If you do not want this or for some reason cannot mv the files afterwards to different locations you will have to create the tar archive in such a way that allows to extract files to a flat hierarchy. You could pipe a list of filenames to tar like this:

echo *txt | tar -cvf my.tar

"my.tar" would contain all the *txt files in the current directory and you could extract an arbitrary subset of these with the mechanism sketched above.

I hope this helps.

Old Unix and Linux 12-02-2008
Neo's Unix or Linux Image
Neo Neo is offline Forum Staff  
Join Date: Sep 2000
Last Activity: 30 April 2017, 11:55 PM EDT
Location: Asia pacific region
Posts: 13,554
Thanks: 843
Thanked 1,124 Times in 526 Posts
Well, this is not the way I would do it, but in theory you could create a symbolic link, linking samba to the current directory and untar in that (current) directory Linux

Not sure why you would do it, but it is possible by creating the symlink.
Sponsored Links
Old Unix and Linux 12-02-2008
shockneck's Unix or Linux Image
shockneck shockneck is offline Forum Advisor  
No RISC - No Fun
Join Date: Mar 2008
Last Activity: 24 January 2011, 4:56 AM EST
Posts: 465
Thanks: 1
Thanked 14 Times in 13 Posts
Originally Posted by allwin View Post
How can i untar a set of files in to different directory.
You might try pax:

# pax -rpe -f /tmp/samba.tar -s :^/samba:/newdir1/newdir2:g

Wrote from memory, but the above command sample should restore files from /samba into /newdir1/newdir2. Read the man page and adapt to your needs.
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Not able to untar file aks_1902 Shell Programming and Scripting 5 11-02-2011 04:31 AM
tar/untar over ssh chuikingman Red Hat 0 09-08-2011 12:43 AM
untar & unzip brendan76 Linux 1 01-16-2008 02:50 AM
Untar problems vinothg UNIX for Dummies Questions & Answers 2 11-09-2007 12:27 AM
untar prakash96453 UNIX for Advanced & Expert Users 2 10-19-2007 01:59 AM

All times are GMT -4. The time now is 12:25 AM.