View previous topic :: View next topic |
Author |
Message |
dylan_stark Tux's lil' helper
Joined: 30 Aug 2005 Posts: 135 Location: Belgrade, Serbia
|
Posted: Thu Jan 01, 2009 12:08 pm Post subject: tar unpacking and removing directory structure |
|
|
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 |
|
|
Tin Guru
Joined: 22 Dec 2005 Posts: 305 Location: Namur, Belgium
|
Posted: Thu Jan 01, 2009 12:12 pm Post subject: |
|
|
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)
_________________ Tin, the gentoobie |
|
Back to top |
|
|
dylan_stark Tux's lil' helper
Joined: 30 Aug 2005 Posts: 135 Location: Belgrade, Serbia
|
Posted: Thu Jan 01, 2009 1:54 pm Post subject: |
|
|
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 |
|
|
Tin Guru
Joined: 22 Dec 2005 Posts: 305 Location: Namur, Belgium
|
Posted: Thu Jan 01, 2009 2:16 pm Post subject: |
|
|
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) _________________ Tin, the gentoobie |
|
Back to top |
|
|
dylan_stark Tux's lil' helper
Joined: 30 Aug 2005 Posts: 135 Location: Belgrade, Serbia
|
Posted: Fri Jan 02, 2009 8:44 pm Post subject: |
|
|
You've been great help. Thanks |
|
Back to top |
|
|
Tin Guru
Joined: 22 Dec 2005 Posts: 305 Location: Namur, Belgium
|
Posted: Fri Jan 02, 2009 9:35 pm Post subject: |
|
|
dylan_stark wrote: | You've been great help. Thanks |
You are welcome. It's my pleasure
For one time, it is not me that ask the question _________________ Tin, the gentoobie |
|
Back to top |
|
|
|