linux - 如何使用 'cp'命令排除特定目录?

标签 linux bash terminal command cp

我想复制一个目录中的所有文件,除了特定子目录中的一些文件。 我注意到 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/

相关文章:

linux - 在 SSH 服务器上运行本地脚本

python - 如何在 'oh-my-zsh' 中显示 Python 版本

linux - 如何使用 bash 别名作为命令行参数

swift - 如何查看我使用的是哪个版本的 Swift?

github - 调用gitk后如何继续使用GitBash?

linux - 将系统调用读取到 x86_64 上 nasm 中的 mmap 分配缓冲区后,文件描述符错误

linux - 每次打开 Ubuntu 终端时 Bash 都没有这样的文件或目录

django - 无需控制键即可停止 Django 服务器

c++ - 显示环境变量 LD_LIBRARY_PATH

bash - 将简单的 shell 脚本作为 cronjob 运行