[英]Copy files to directory if they are not in another directory
我有四個文件file1, file2, file3, file4
。
目錄/All
包含所有四個文件,目錄/A
包含file1, file2
。 現在我想將 rest file3, file4
復制到另一個目錄/B
。 如何在命令行中執行此操作?
感謝您的幫助。
find ./All/ -type f -exec bash -c '[ ! -e "./A/$(basename "$0")" ] && cp "$0" ./B/' '{}' \;
如果需要,以下解決方案(在bash
中)將支持文件名中的空格,但不支持子目錄。
diff <(\ls /A) <(\ls /All) | egrep '^> ' | cut -b 3- | xargs -d'\n' -I {} cp "/All/{}" "/B/{}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.