排除s3cmd同步的点文件

时间:2014-01-04 10:48:09

标签: s3cmd

如何排除主目录中的所有点文件以及所有子目录中的点文件?

我已尝试在我的排除文件中添加以下表达式,但由于某种原因它不起作用:

(^|/)\.[^/]*(/|$)

此外,以下内容也不起作用:

.*
.*/**

1 个答案:

答案 0 :(得分:5)

请先使用选项--dry-run尝试以下命令,以确保获得预期的结果。

从当前目录中排除.dotfiles和.folders

您可以使用选项--rexclude "^\."来匹配以.开头的文件和文件夹(但它与子目录中的.dotfiles不匹配)。

s3cmd sync --rexclude "^\." ./ s3://bucket_name

的输出示例
exclude: .ignoreFile
exclude: .ignoreFolder/andItsContents
./normalFolder/.ignoreFile -> s3://bucket_name/normalFolder/.ignoreFile

上面的命令,在当前文件夹中排除.dotfiles。并继续上传  normalFolder / .ignoreFile

从子目录

中排除.dotfiles

要从子目录中排除dotfiles,您可以使用--rexclude "\/\."

s3cmd sync --rexclude "\/\." ./ s3://bucket_name

的输出示例
exclude: .ignoreThis
exclude: .ignoreFolder/.ignoreThis
exclude: .ignoreFolder/notadotfile
exclude: normalFolder/.ignoreThis

因此,您的问题的答案应类似于以下命令:

s3cmd --rexclude "^\." --rexclude "\/\." ./ s3://bucket_name

使用的正则表达式锚的说明:

^   Start of string, or start of line in multi-line pattern
\   Escape following character

有用的参考:
Regular Expressions Cheat Sheet

s3cmd Sync HowTo