rsync:如何仅在最顶层目录中排除 Dotfiles?

8 bash rsync regex

在 Bash 下使用 执行备份时rsync,我试图排除顶级目录中的所有点文件和隐藏目录,但排除其他目标目录中的那些。例如:

/copyme.c  
/.dontcopythisfile  
/.dontcopythisdirectory/or_its_contents  
/directory/.butcopymetoo
Run Code Online (Sandbox Code Playgroud)

rsync -a --include=".includeme" --exclude=".*" . DEST无法复制子目录中所需的点文件,但诸如此类的变体--exclude="./.*"也失败。

建议?这是否需要过滤规则而不是更简单的规则--exclude

Ale*_*yak 12

您应该使用锚点,并且在 rsync 中,锚点字符是“/”。

所以在你的字符串中应该是:

rsync -a --include="/.includeme" --exclude="/.*" ./ DEST
Run Code Online (Sandbox Code Playgroud)