untar

Hi,

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
Allwin

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.

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.

bakunin

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 :smiley:

Not sure why you would do it, but it is possible by creating the symlink.

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.