rsync - 包含与 rsync 中排除的其他文件夹同名的文件夹

标签 rsync

所以我有这个代码:

rsync \
   --archive \
   --verbose \
   --compress \
   --delete \
   --no-motd \
   --exclude=.git* \
   --exclude=.idea \
   --exclude=.tags \
   --exclude=vendor \
   --exclude=tags \
   --exclude=node_modules \
   --rsync-path="sudo rsync" \
   "${src}"/ \
   "${profile}":"${dst}"

而且效果很漂亮!但我有一个问题......这个树结构:

.
├── app
│   ├── vendor/
├── vendor/

它不起作用。我只想排除 ./vendor 但包含 ./app/vendor。我尝试过使用 --include 但结果是相同的:app/vendor 始终被排除。

最佳答案

有两种方法可以做到这一点:

  1. 使用--include:

    rsync \
       .... \
       --include=app/vendor \
       --exclude=vendor \
       ....
    

    即将 --include 放在 --exclude

  2. 之前
  3. 使用更具体的--exclude:

    rsync \
        .... \
        --exclude=/vendor \
        ....
    

    即仅排除源目录根目录中的供应商(不要与文件系统根目录混淆)。

包含/排除规则的基本规则是 rsync 将使用匹配任何给定文件的第一个规则。您将特定规则放在顶部,将一般规则放在底部。如果您向后查看它们,您会发现您的特定覆盖不起作用。

关于rsync - 包含与 rsync 中排除的其他文件夹同名的文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36518966/

相关文章:

macos - 在 OS X 中设置文件时间戳的 API

linux - 为什么这个 rsync 命令没有删除?

ssh - 在ssh/rsync到远程目标之后,目标机器如何在传输完成后立即知道新文件?

rsync - 使用 rsync glob 复制文件夹结构

linux - rsync 设置错误组

reactjs - 缺少更新 GCloud 上静态 ReactJS 站点的步骤

linux - 两台服务器之间的远程 rsync 管道损坏

shell - GNU 与 rsync 并行

ruby - Dropbox 类似 git 的服务——没有 rsync 和 inotify

rsync - 关于使用 Rsync 的几个问题?