我有一个目录结构的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发布于 2016-02-05 04:12:00
一系列真正具体的正则表达式解决了这个问题:
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 _directorieshttps://stackoverflow.com/questions/35210686
复制相似问题