Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
tar unpacking and removing directory structure
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
dylan_stark
Tux's lil' helper
Tux's lil' helper


Joined: 30 Aug 2005
Posts: 132
Location: Belgrade, Serbia

PostPosted: Thu Jan 01, 2009 12:08 pm    Post subject: tar unpacking and removing directory structure Reply with quote

I'm trying to do some copying over network with ssh and tar

Code:
ssh root@host tar -cf - /vdata/0/50/13350/some_data | tar -xf - -C .


and everything works fine, I just can't figure out how NOT to keep directory structure on the destination host.
Now it's all going/unpacking to vdata/0/50/13350/some_data and I want it to go just to some_data.
Back to top
View user's profile Send private message
Tin
Guru
Guru


Joined: 22 Dec 2005
Posts: 303
Location: Namur, Belgium

PostPosted: Thu Jan 01, 2009 12:12 pm    Post subject: Reply with quote

Damd stupid, but so simple :
Code:

ssh root@host "cd /vdata/0/50/13350/;tar -cf - some_data" | tar -xf - -C .

you can remove the -f flag to play with stdin and stdout
and the -C too if you don't want to change directory
Code:

ssh root@host "cd /vdata/0/50/13350/;tar -c some_data" | tar -x

(don't forget the quotes)
:wink:
_________________
Tin, the gentoobie
Back to top
View user's profile Send private message
dylan_stark
Tux's lil' helper
Tux's lil' helper


Joined: 30 Aug 2005
Posts: 132
Location: Belgrade, Serbia

PostPosted: Thu Jan 01, 2009 1:54 pm    Post subject: Reply with quote

Thank you, that's it!
But I can't belive tar doesn't have some built-in option for something like this....
Back to top
View user's profile Send private message
Tin
Guru
Guru


Joined: 22 Dec 2005
Posts: 303
Location: Namur, Belgium

PostPosted: Thu Jan 01, 2009 2:16 pm    Post subject: Reply with quote

There is no option of file copy/move with tar because it is not a file copy/move program but an archiver (even if it is really good at remote copy)
The only file modifications that tar can do is to avoid problems related to archives restorations (file permissions, timestamps, remove the first / of the absolute pathnames, links, etc...)

Imagine the amount of problematic situation if tar should manage such file manipulation in these kind of case :
Code:

ehilson@rebel ~/tmp $ tree example
example
|-- dir1
|   |-- file1
|   `-- file2
`-- dir2
    |-- dir3
    |   `-- file2
    `-- file2


(especially if file2 is named xorg.conf ;-) )

If you really want to flatten all the files of a directory tree, just play with that command after the archive extraction or before the archive creation :

Code:

find my_source_directory | while read f;do cp "$f" my_target_directory/$(basename "$f");done

It will copy all your files into one directory : my_target_directory

Be aware that it won't work if some directories/files contains space in their name.
For that, read the man page of "find' command to play with the "-exec" option :-)
(I am too lazy for to do it) :wink:
_________________
Tin, the gentoobie
Back to top
View user's profile Send private message
dylan_stark
Tux's lil' helper
Tux's lil' helper


Joined: 30 Aug 2005
Posts: 132
Location: Belgrade, Serbia

PostPosted: Fri Jan 02, 2009 8:44 pm    Post subject: Reply with quote

You've been great help. Thanks :wink:
Back to top
View user's profile Send private message
Tin
Guru
Guru


Joined: 22 Dec 2005
Posts: 303
Location: Namur, Belgium

PostPosted: Fri Jan 02, 2009 9:35 pm    Post subject: Reply with quote

dylan_stark wrote:
You've been great help. Thanks :wink:


You are welcome. It's my pleasure ;-)

For one time, it is not me that ask the question ;-) :roll:
_________________
Tin, the gentoobie
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum