# tar unpacking and removing directory structure

## dylan_stark

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

```
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.

----------

## Tin

Damd stupid, but so simple :

```

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

```

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

```

(don't forget the quotes)

 :Wink: 

----------

## dylan_stark

Thank you, that's it!

But I can't belive tar doesn't have some built-in option for something like this....

----------

## Tin

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 :

```

ehilson@rebel ~/tmp $ tree example

example

|-- dir1

|   |-- file1

|   `-- file2

`-- dir2

    |-- dir3

    |   `-- file2

    `-- file2

```

(especially if file2 is named xorg.conf  :Wink:  )

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 :

```

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

(I am too lazy for to do it)   :Wink: 

----------

## dylan_stark

You've been great help. Thanks  :Wink: 

----------

## Tin

 *dylan_stark wrote:*   

> You've been great help. Thanks 

 

You are welcome. It's my pleasure  :Wink: 

For one time, it is not me that ask the question  :Wink:   :Rolling Eyes: 

----------

