请原谅我的英语不好。我只想将特定目录(serenity)内现有的图像(.png)复制到另一个目录,而忽略其中的子目录(数据表、图像等)。
find /home/user/Selenium_new/Staf/target/site/serenity/ -iname "*.png"
我使用上述命令获取 serenity 目录中存在的所有图像,但它也获取子目录中的图像。该命令的结果是:
/home/user/Selenium_new/Staf/target/site/serenity/images/success.png
/home/user/Selenium_new/Staf/target/site/serenity/images/menu_h.png
/home/user/Selenium_new/Staf/target/site/serenity/images/driver-chrome.png
/home/user/Selenium_new/Staf/target/site/serenity/images/ico-q.png
/home/user/Selenium_new/Staf/target/site/serenity/images/driver-appium.png
/home/user/Selenium_new/Staf/target/site/serenity/images/cross.png
/home/user/Selenium_new/Staf/target/site/serenity/images/small-middle.png
/home/user/Selenium_new/Staf/target/site/serenity/images/fail.png
/home/user/Selenium_new/Staf/target/site/serenity/images/driver-iexplorer.png
/home/user/Selenium_new/Staf/target/site/serenity/images/screen.png
/home/user/Selenium_new/Staf/target/site/serenity/images/ignor.png
/home/user/Selenium_new/Staf/target/site/serenity/images/menu_s.png
/home/user/Selenium_new/Staf/target/site/serenity/images/driver-remote.png
/home/user/Selenium_new/Staf/target/site/serenity/images/worker.png
/home/user/Selenium_new/Staf/target/site/serenity/images/driver-phantomjs.png
/home/user/Selenium_new/Staf/target/site/serenity/images/driver-safari.png
/home/user/Selenium_new/Staf/target/site/serenity/images/serenity-bdd-logo.png
/home/user/Selenium_new/Staf/target/site/serenity/images/video.png
/home/user/Selenium_new/Staf/target/site/serenity/images/small-middle-right.png
/home/user/Selenium_new/Staf/target/site/serenity/images/tick.png
/home/user/Selenium_new/Staf/target/site/serenity/images/plus.png
/home/user/Selenium_new/Staf/target/site/serenity/images/pending.png
/home/user/Selenium_new/Staf/target/site/serenity/images/menu_f.png
/home/user/Selenium_new/Staf/target/site/serenity/images/skip.png
/home/user/Selenium_new/Staf/target/site/serenity/images/driver-provided.png
/home/user/Selenium_new/Staf/target/site/serenity/images/driver-htmlunit.png
/home/user/Selenium_new/Staf/target/site/serenity/images/links_menu.png
/home/user/Selenium_new/Staf/target/site/serenity/images/minus.png
/home/user/Selenium_new/Staf/target/site/serenity/images/driver-opera.png
/home/user/Selenium_new/Staf/target/site/serenity/images/driver-firefox.png
/home/user/Selenium_new/Staf/target/site/serenity/9f5dedcc05678478e7511bb10f9fe15d_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/4a6c5da6264596f2e28453381a0958a2_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/d08552dd3fc9a718eda02eb432d35db1_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/2e756d0187d17ff7ede129c0cd26d5ed_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/3781a9f41cb06adbf2bcab99315e5016_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/jqtree/0.22/jqtree-circle.png
/home/user/Selenium_new/Staf/target/site/serenity/e4a22a00e04d0f54c7306e49a88e3a2c_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/0683540c982a0550834aaea79d71942a_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/76007c6a74590dce97d26dedf8344926_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/ab38399ff5f8b5222e8106c805b97e14_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/fb0cb5df5880626b23643f399bfc5b62_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/datatables/1.10.4/media/images/sort_asc.png
/home/user/Selenium_new/Staf/target/site/serenity/datatables/1.10.4/media/images/sort_desc.png
/home/user/Selenium_new/Staf/target/site/serenity/datatables/1.10.4/media/images/forward_enabled_hover.png
/home/user/Selenium_new/Staf/target/site/serenity/datatables/1.10.4/media/images/sort_desc_disabled.png
/home/user/Selenium_new/Staf/target/site/serenity/datatables/1.10.4/media/images/forward_enabled.png
/home/user/Selenium_new/Staf/target/site/serenity/datatables/1.10.4/media/images/back_enabled_hover.png
/home/user/Selenium_new/Staf/target/site/serenity/datatables/1.10.4/media/images/sort_asc_disabled.png
/home/user/Selenium_new/Staf/target/site/serenity/datatables/1.10.4/media/images/forward_disabled.png
/home/user/Selenium_new/Staf/target/site/serenity/datatables/1.10.4/media/images/back_enabled.png
/home/user/Selenium_new/Staf/target/site/serenity/datatables/1.10.4/media/images/sort_both.png
/home/user/Selenium_new/Staf/target/site/serenity/datatables/1.10.4/media/images/back_disabled.png
/home/user/Selenium_new/Staf/target/site/serenity/9f364046fc0272688aa06a3fb71b8ded_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/644d968b7f1b2979841ae07223d1f860_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/85fcef5aa335c83a53d5d31da56b9fe3_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/29e3a91e22d17dc12be045deae496d93_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-bg_glass_45_0078ae_1x400.p
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-icons_056b93_256x240.png
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-bg_gloss-wave_75_2191c0_50
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-icons_d8e7f3_256x240.png
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-bg_glass_55_f8da4e_1x400.p
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-bg_flat_55_999999_40x100.p
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-icons_0078ae_256x240.png
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-bg_glass_75_79c9ec_1x400.p
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-icons_e0fdff_256x240.png
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-bg_inset-hard_100_fcfdfd_1
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-icons_f5e175_256x240.png
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-icons_fcd113_256x240.png
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-bg_gloss-wave_45_e14f1c_50
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-icons_f7a50d_256x240.png
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-bg_gloss-wave_50_6eac2c_50
/home/user/Selenium_new/Staf/target/site/serenity/jqueryui/1.11.2-start/images/ui-bg_flat_75_aaaaaa_40x100.p
/home/user/Selenium_new/Staf/target/site/serenity/1dff59ff9f9aeacc1158f993154c5780_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/jit/css/col2.png
/home/user/Selenium_new/Staf/target/site/serenity/jit/css/col1.png
/home/user/Selenium_new/Staf/target/site/serenity/jit/css/gradient.png
/home/user/Selenium_new/Staf/target/site/serenity/acca1aa0392b5b4061b7010cbdf78d25_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/c47b46d36817b6d09b332d03237f41c1_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/8b059de51307d713150b9bff578302ef_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/nivo-slider/3.2/demo/images/dev7logo.png
/home/user/Selenium_new/Staf/target/site/serenity/nivo-slider/3.2/themes/light/arrows.png
/home/user/Selenium_new/Staf/target/site/serenity/nivo-slider/3.2/themes/light/bullets.png
/home/user/Selenium_new/Staf/target/site/serenity/nivo-slider/3.2/themes/default/arrows.png
/home/user/Selenium_new/Staf/target/site/serenity/nivo-slider/3.2/themes/default/bullets.png
/home/user/Selenium_new/Staf/target/site/serenity/nivo-slider/3.2/themes/bar/arrows.png
/home/user/Selenium_new/Staf/target/site/serenity/nivo-slider/3.2/themes/bar/bullets.png
/home/user/Selenium_new/Staf/target/site/serenity/nivo-slider/3.2/themes/dark/arrows.png
/home/user/Selenium_new/Staf/target/site/serenity/nivo-slider/3.2/themes/dark/bullets.png
/home/user/Selenium_new/Staf/target/site/serenity/97e00cdb9c0e090e8f012cca67fc38e2_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/23d7196aa4430b6e75bd6c7106693cc1_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/6cc23a7c739909acd59a723e16e56c9c_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/92052104972408175031d00e90a48543_NONE.png
问题 1:如何获取仅存在于目录(serenity)中的所有图像,而不是来自子目录(图像、数据表......等)的图像?
/home/user/Selenium_new/Staf/target/site/serenity/97e00cdb9c0e090e8f012cca67fc38e2_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/23d7196aa4430b6e75bd6c7106693cc1_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/6cc23a7c739909acd59a723e16e56c9c_NONE.png
/home/user/Selenium_new/Staf/target/site/serenity/92052104972408175031d00e90a48543_NONE.png
问题 2:如何将上述图像(目录图像)复制到另一个目录(/home/user/temp)?
答案1
为什么还要使用find
?
cp /path/to/dir/*.png /path/to/secondDir/
将所有 png 图像从第一个目录复制到第二个目录。
答案2
如果您出于某种原因想要使用find
而不是那么cp
您必须使用-maxdepth
带有以下选项1
:
find /path/to/directory -type f -maxdepth 1 -iname "*.png"
它仅查看指定的目录而不查看子目录。
复制:
find /path/to/directory -type f -maxdepth 1 -iname "*.png" -exec cp {} /home/user/temp \;
-maxdepth levels
下降至起点以下最多层数(非负整数)的目录层数。