從特定目錄中尋找所有 jpg 映像並將其複製到其他目錄

從特定目錄中尋找所有 jpg 映像並將其複製到其他目錄

如何將目錄中存在的所有 jpg 圖像 [名稱以 .jpg 結尾的檔案] 複製/usr/share/backgrounds到 jpg 目錄中,/week/pictures/final/jpg然後重定向檔案中可能出現的任何錯誤訊息cp.err

cp *.jpg /usr/share/background /home/userName/week/pictures/final/jpg | ls 2>cp.err

我想可能就是這樣了。有人可以澄清一下嗎?

答案1

嘗試:
cp /usr/share/backgrounds/*.jpg /week/pictures/final/jpg/ 2> cp.err

請注意,該cp.err檔案將在執行該命令時所在的目錄中建立。如果您希望錯誤檔案位於不同的目錄中,您可以執行以下操作:
cp /usr/share/backgrounds/*.jpg /week/pictures/final/jpg/ 2> /desired_directory/cp.err

答案2

嘗試使用find命令:

find /usr/share/backgrounds -iname "*.jpg" -type f -exec /bin/cp {} /week/pictures/final/jpg 2>cp.err \;

相關內容