【问题标题】:Excluding dot files for s3cmd sync排除 s3cmd 同步的点文件
【发布时间】:2014-01-04 10:48:09
【问题描述】:

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

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

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

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

.*
.*/**

【问题讨论】:

    标签: s3cmd


    【解决方案1】:

    请先尝试以下带有选项--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

    要从子目录中排除点文件,您可以使用--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

    【讨论】:

    • 我现在看到了我的问题,谢谢。当我应该使用 --rexclude-from=FILE 时,我在我的排除文件中错误地使用了正则表达式 --exclude-from=FILE。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    相关资源
    最近更新 更多