有没有办法使用命令'cp'复制目录并排除其中的某些文件/子目录?
使用rsync
:
rsync -av --exclude='path1/to/exclude' --exclude='path2/to/exclude' source destination
请注意,使用source
和source/
是不同的。尾部斜杠表示将文件夹source
的内容复制到destination
中。如果没有尾部斜杠,则表示将文件夹源复制到destination
。
或者,如果要排除许多目录(或文件),可以使用--exclude-from=FILE
,其中FILE
是一个名称。包含要排除的文件或目录的文件。
--exclude
也可能包含通配符,例如--exclude=*/.svn*
已复制自: https://stackoverflow.com/a/2194500/749232
如果您想使用cp
本身:
find . -type f -not -iname '*/not-from-here/*' -exec cp '{}' '/dest/{}' ';'
这假定目标目录结构与源的结构相同。
已复制自: https://stackoverflow.com/a/4586025/749232