我想复制一个目录中的所有文件,除了特定子目录中的一些文件。
我注意到 cp
命令没有 --exclude
选项。
那么,我该如何实现呢?
最佳答案
rsync
既快速又简单:
rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude
您可以多次使用--exclude
。
rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude --exclude anotherfoldertoexclude
请注意,--exclude
选项之后的目录 thefoldertoexclude
是相对于 sourcefolder
的,即 sourcefolder/thefoldertoexclude
.
您还可以添加 -n
进行试运行,以查看在执行实际操作之前将复制的内容,如果一切正常,请从命令行中删除 -n
。
关于linux - 如何使用 'cp'命令排除特定目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42952706/