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

天大地大妈咪最大 提交于 2019-11-30 11:56:56

问题


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


回答1:


you are looking for ways to flatten the directory

find /images -iname '*.jpg' -exec cp --target-directory /newfolder/ {} \;

find all files iname in case insensitive name mode.
cp copy once to --target-directory named /newfolder/.
{} expand the list from find into the form of /dir/file.jpg /dir/dir2/bla.jpg.




回答2:


find /source-tree -type f -exec cp {} /target-dir \;



回答3:


On zsh:

cp /source/**/* /destination




回答4:


$ cd images && cp ** new_folder/


来源:https://stackoverflow.com/questions/9800989/copy-every-file-of-entire-directory-structure-into-base-path-of-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!