You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在AWS S3 CLI中使用通配符仅匹配当前目录文件?

Great question! I totally get why unnecessary subdirectory traversal is frustrating—it’s a waste of time when you only care about files in your current working directory. Let’s break down how to fix this efficiently.

First, the root issue with your original command: the --recursive flag tells the AWS CLI to walk through every subdirectory under your current path. Even though you exclude */*, the CLI still has to scan each subdirectory first before applying the exclude rule. That’s the unnecessary overhead you’re seeing.

Here are two optimized solutions that eliminate subdirectory traversal entirely:

Option 1: Use Shell Wildcards (Simplest & Most Efficient)

Let your shell handle the file matching instead of relying on AWS CLI filters. This way, you only pass the exact files you want to the CLI, so it never even looks at subdirectories:

aws s3 cp --dryrun *.log s3://my-bucket/folder/

Your shell will expand *.log to a list of all .log files in the current directory before running the command. The AWS CLI only processes those specific files—no subdirectory scanning happens at all.

Option 2: Skip --recursive & Use CLI Filters

If you prefer using AWS CLI’s own filtering (useful for more complex patterns), just remove the --recursive flag. Without it, the CLI only operates on files in the current directory, so your include/exclude rules apply only there:

aws s3 cp --dryrun --exclude "*" --include "*.log" . s3://my-bucket/folder/

Since we’re not forcing recursion, the CLI won’t traverse any subdirectories. The --exclude "*" rule blocks all files by default, then --include "*.log" re-includes the files you want in your current directory.

Why These Are Better Than Your Original Command

Both options ditch the --recursive flag, which was causing the unnecessary subdirectory scan. Your original command forced the CLI to walk every subdirectory before excluding it—these solutions skip that step entirely, making them faster and cleaner.

内容的提问来源于stack exchange,提问作者cartbramer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:41:02