[英]Exclude directory while copy directory
I want to exclude two directories while copying.我想在复制时排除两个目录。
Example:例子:
$ ls /root/tmp
a b c d e f
I want to exclude directories a
and b
:我想排除目录a
和b
:
$ cp -rp /root/tmp/ /root/tmp1/
rsync
can be used to exclude multiple directories like this: rsync
可用于排除多个目录,如下所示:
rsync -av --exclude=/root/tmp/a --exclude=/root/tmp/b /root/tmp/ /root/tmp1/
with cp
command用cp
命令
cp -r /root/tmp/!(a | b) /root/tmp1/
Execute shopt -s extglob
before cp
command to enable !
在cp
命令之前执行shopt -s extglob
以启用!
in cp
在cp
Try the below rsync
it works for me on ubuntu 14.04
试试下面的rsync
它在ubuntu 14.04
上对我有用
rsync -av --exclude='/root/tmp/a' --exclude='/root/tmp/b'
/path/to/include /path/to/include /path/to/destination
You could exclude the directories as part of find results before the copy, but using rsync
or cp
with the '!'
您可以在复制之前将目录排除为查找结果的一部分,但使用带有'!'
rsync
或cp
support enabled as suggested by Sathiya is a much simpler solution. Sathiya 建议启用的支持是一个更简单的解决方案。
See find
example below:请参阅下面的find
示例:
find /root/tmp/ -mindepth 1 -maxdepth 1 -type d ! -regex '\(.*a\|.*b\)' -exec cp -r {} /root/tmp1/ \;
You can do this in bash (does not work in sh):您可以在 bash 中执行此操作(在 sh 中不起作用):
shopt -s extglob
cp -r !(somefile|somefile2|somefolder) destfolder/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.