首页 > 解决方案 > In this AWS CLI command, why copying files with --exclude & --include wildcards not working?

问题描述

In the following directory, I want to upload only the .html files in top /DirA/ to the root of my AWS bucket:

/DirA/, e.g.

.file
fileA.html
fileB.html
fileC.bin
/subdirA
/subdirB

When I run the this:

me@me:/DirA$ aws s3 cp ./ s3://MYBUCKET/ --dryrun --exclude "*" --include "*.html"

The .html files are not handled by aws and I just get the empty prompt me@me:/DirA$ back. No error or the usual (dry run) upload: message.

I have also tried

me@me:/$ aws s3 cp /DirA/ s3://MYBUCKET/ --dryrun --exclude "*" --include "*.html"

with the same empty prompt.

Please note (if helpful):

  1. The above were in Ubuntu 18.04 with latest installed AWS CLI v1.
  2. I also installed AWS CLI in Windows and did the same, with similar empty result.
  3. Uploading stuff which does not require --exclude or --include like that works normally

What am I doing wrong and how to fix that. Thank you very much.

标签: windowsamazon-web-servicesubuntuamazon-s3aws-cli

解决方案


josedasilva是对的,你需要使用--recursive旗帜。现在,要仅包含当前目录文件,您需要混合一些包含和排除标志。

这应该做的工作:

aws s3 cp --recursive ./ s3://MYBUCKET/ --exclude "*" --include "*.html" --exclude "*/*"

推荐阅读