Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glob pattern with amazon s3

I want to move files from one s3 bucket to another s3 bucket.I want to move only files whose name starts with "part".I can do it by using java.But is it possible to do it with amazon CLI. Can we use GlobPattern in CLI. my object name are like: part0000 part0001

like image 213
Smily Avatar asked Oct 17 '25 22:10

Smily


1 Answers

Yes, this is possible through the aws CLI, using the --include and --exclude options.

As an example, you can use the aws s3 sync command to sync your part files:

aws s3 sync --exclude '*' --include 'part*' s3://my-amazing-bucket/ s3://my-other-bucket/

You can also use the cp command, with the --recursive flag:

aws s3 cp --recursive --exclude '*' --include 'part*' s3://my-amazing-bucket/ s3://my-other-bucket/

Explanation:

  • aws: The aws CLI command
  • s3: The aws service to interface with
  • sync: The command to the service to do
  • --exclude <value>: The UNIX-style wildcard to ignore, except by include statements
  • --include <value>: The UNIX-style wildcard to act upon.

As noted in the documentation, you can also specify --include and --exclude multiple times.

like image 180
jwang Avatar answered Oct 20 '25 13:10

jwang