简体   繁体   English

如果文件不在另一个目录中,则将文件复制到目录

[英]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.

相关问题 CentOS:将目录复制到另一个目录 - CentOS: Copy directory to another directory “查找”目录下的所有.log文件,将它们复制到以其父目录命名的另一个目录? - 'find' all .log files under a directory, copy them to another directory named after their parent directory? 如何在Linux中将具有特定扩展名的文件从一个目录复制到另一个目录 - How to copy files with a particular extension from one directory to another in linux 将具有特定扩展名的所有文件复制到另一个目录,同时更改扩展名 - Copy all files with certain extension to another directory, while changing the extension 通过bash将文件从一个目录排序并复制到另一个目录 - Sort and copy files from one directory to another via bash 如何将具有相同后缀的所有文件复制到另一个目录? -Unix - How to copy all the files with the same suffix to another directory? - Unix 使用bash脚本将两个最新文件复制到另一个目录 - Copy two most recent files to another directory using bash script 如何将文件从 linux 目录复制到另一个给定长度参数 - How to copy files from a linux directory to another given a length parameter 使用 Linux 将特定数量的文件从一个目录复制到另一个 - Copy specific number of files from on directory to another using Linux 如何将目录及其子目录中的所有文件复制到另一个目录? - How to copy all files from a directory and its subdirectories to another dir?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM