Linux 将整个目录结构的每个文件复制到另一个的基本路径中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9800989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:18:23  来源:igfitidea点击:

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

linuxbashfinddirectorycp

提问by csch

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?

我很确定有一个 bashcommand,但我还没有找到它。你有什么想法?

CS

CS

采纳答案by cctan

you are looking for ways to flatten the directory

您正在寻找展平目录的方法

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

findall files inamein case insensitive name mode.
cpcopy once to --target-directorynamed /newfolder/.
{}expand the list from findinto the form of /dir/file.jpg /dir/dir2/bla.jpg.

findiname不区分大小写名称模式的所有文件。
cp复制一次到--target-directorynamed /newfolder/
{}将列表从 展开find为 的形式/dir/file.jpg /dir/dir2/bla.jpg

回答by Kaz

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

回答by Grégory Roche

$ cd images && cp ** new_folder/

回答by gbin

On zsh:

zsh 上

cp /source/**/* /destination

cp /source/**/* /destination