【问题标题】:How do I exclude hidden files and directories when using gsutil to rsync?使用 gsutil 进行 rsync 时如何排除隐藏文件和目录?
【发布时间】:2016-05-14 15:15:06
【问题描述】:

我有一个 Jekyll 博客,其目录结构包含许多隐藏文件和目录,例如 .DS_Store.idea.git。它还具有以_ 开头的中间构建工件和脚本,例如_deploy.sh_drafts

我想编写一个脚本,将所有内容上传到 Google Cloud Storage 上的存储桶中,除了这些隐藏文件和带下划线的工件。

我尝试使用-x 标志,但我的表达式要么排除整个当前目录,不上传任何内容,要么未能排除一些我想排除的内容。

这是我目前所拥有的:

#!/bin/sh
gsutil -m rsync -rx '\..*|./[.].*$|_*' ./ gs://my-bucket.com/path

我正在观察的输出:

$  ./_deployblog.sh
Building synchronization state...
Starting synchronization

【问题讨论】:

    标签: jekyll google-cloud-storage google-cloud-platform gsutil


    【解决方案1】:

    一系列非常具体的正则表达式解决了这个问题:

    gsutil -m rsync -rdx '\..*|.*/\.[^/]*$|.*/\..*/.*$|_.*' . gs://my-bucket.com/path
    

    其中排除模式有 4 个组件,由 | 字符分隔。

    \..*        <- excludes .files and .directories in the current directory
    .*/\.[^/]*$ <- excludes .files in subdirectories
    .*/\..*/.*$ <- excludes .directories in subdirectories
    _.*         <- excludes _files and _directories
    

    【讨论】:

    • 这可以缩短为-x '(^|/)(_|\.)':当有路径开头或/ 后跟_. 时,我们会选择文件
    猜你喜欢
    • 2016-02-15
    • 2020-03-20
    • 2019-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    • 2013-12-27
    相关资源
    最近更新 更多