[英]Copy files to directory if they are not in another directory
I have four files file1, file2, file3, file4
.我有四个文件file1, file2, file3, file4
。
A directory /All
contains all four files, a directory /A
contains file1, file2
.目录/All
包含所有四个文件,目录/A
包含file1, file2
。 Now I want to copy the rest file3, file4
to another directory /B
.现在我想将 rest file3, file4
复制到另一个目录/B
。 How can I do this in the command line?如何在命令行中执行此操作?
Thank you for the help.感谢您的帮助。
find ./All/ -type f -exec bash -c '[ ! -e "./A/$(basename "$0")" ] && cp "$0" ./B/' '{}' \;
The following solution (in bash
) will support spaces in filenames if you need, although not subdirectories.如果需要,以下解决方案(在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.