How to use aws s3 cp wildcards to copy group of files in AWS CLI?

21.7K    Asked by FukudaAshikaga in AWS , Asked on Apr 20, 2021

I am unable to copy some files from a S3 bucket in AWS CLI

Adding * to the path is not helping:

aws s3 cp s3://personalfiles/file* 

Don’t know how to use aws s3 cp wildcard. Please help

Answered by Fukuda Ashikaga

To download multiple files from an aws bucket to your current directory, you can use recursive , exclude , and include flags. The order of the parameters matters. The exclude and include should be used in a specific order, We have to first exclude and then include.

 You can use 3 high-level S3 commands that are inclusive, exclusive and recursive.

--include and --exclude are used to specify rules that filter the objects or files to be copied during the sync operation or if they have to be deleted

Using recursive command on a file or directory, the command walks the directory tree including all the sub-directories

--exclude "*" --include "*.txt" \All files will be excluded from the command except for files ending with .txt 

--include "*.txt" --exclude "*" \All files will be excluded from the comand

aws s3 cp /tmp/foo/ s3://bucketfiles/ --recursive --exclude "*" --include "*.jpg"
Try the coded provided below:
aws s3 cp s3://personalfiles/ . --recursive --exclude "*" --include "file*”

Your Answer


Parent Categories