Copy every file of entire directory structure into base path of another

csch picture csch · Mar 21, 2012 · Viewed 12.7k times · Source

I have a directory-tree with a lot of files in it. I'd like to copy all of those files into one new directory, but with all files located in the base of the folder.

So I have something like this:

    images
    ├── avatar.png
    ├── bg.jpg
    ├── checkbox.png
    ├── cross.png
    ├── datatables
    │   ├── back_disabled.png
    │   ├── back_enabled.png
    │   ├── forward_disabled.png
    │   ├── forward_enabled.png
    │   ├── sort_asc.png
    │   ├── sort_asc_disabled.png
    │   ├── sort_both.png
    │   ├── sort_desc.png
    │   └── sort_desc_disabled.png
    ├── exclamation.png
    ├── forms
    │   ├── btn_left.gif
    │   ├── btn_right.gif
    │   ├── checkbox.gif
    │   ├── input
    │   │   ├── input_left-focus.gif
    │   │   ├── input_left-hover.gif
    │   │   ├── input_left.gif
    │   │   ├── input_right-focus.gif
    │   │   ├── input_right-hover.gif
    │   │   ├── input_right.gif
    │   │   ├── input_text_left.gif
    │   │   └── input_text_right.gif
    │   ├── radio.gif
    │   ├── select_left.gif
    │   ├── select_right.gif

And I'd like something like this:

    new_folder
    ├── avatar.png
    ├── bg.jpg
    ├── checkbox.png
    ├── cross.png
    ├── back_disabled.png
    ├── back_enabled.png
    ├── forward_disabled.png
    ├── forward_enabled.png
    ├── sort_asc.png
    ├── sort_asc_disabled.png
    ├── sort_both.png
    ├── sort_desc.png
    ├── sort_desc_disabled.png
    ├── exclamation.png
    ├── btn_left.gif
    ├── btn_right.gif
    ├── checkbox.gif
    ├── input_left-focus.gif
    ├── input_left-hover.gif
    ├── input_left.gif
    ├── input_right-focus.gif
    ├── input_right-hover.gif
    ├── input_right.gif
    ├── input_text_left.gif
    ├── input_text_right.gif
    ├── radio.gif
    ├── select_left.gif
    ├── select_right.gif

I'm pretty sure there is a bashcommand for that, but I haven't found it yet. Do you have any ideas?

CS

Answer

Kaz picture Kaz · Mar 21, 2012
find /source-tree -type f -exec cp {} /target-dir \;