About this question
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
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
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask AWS Expert
Answered on Apr 20, 2021
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
Syntax:
--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
Syntax:
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*”
Ranjana Admin JanBask Expert Latest answer
Answered on Jan 28, 2025
Using aws s3 cp with wildcards in AWS CLI is an efficient way to copy groups of files between local systems and S3 buckets or within S3 itself. Here’s a breakdown of how to use it effectively:
1. Syntax for aws s3 cp
aws s3 cp [options]2. Using Wildcards with --recursive
Wildcard Support:
AWS S3 CLI supports shell-style wildcards like * to match multiple files.
Example:
aws s3 cp s3://your-bucket-name/ local-folder/ --recursive --exclude "*" --include "*.txt"3. Copy Specific Groups of Files
To copy files with a specific extension:
aws s3 cp s3://your-bucket-name/ local-folder/ --recursive --include "*.csv"To copy files with a prefix:
aws s3 cp s3://your-bucket-name/ local-folder/ --recursive --include "logs_*"4. Copy Between S3 Locations
You can also use wildcards to copy files between two S3 buckets:
aws s3 cp s3://source-bucket/ s3://destination-bucket/ --recursive --include "*.jpg"5. Exclude Files
To exclude certain file types, use the --exclude flag:
aws s3 cp s3://your-bucket-name/ local-folder/ --recursive --exclude "*.tmp"6. Notes and Limitations
aws s3 cp s3://your-bucket-name/ local-folder/ --recursive --dryrunBy combining wildcards, --include, and --exclude, you can precisely control which files to copy. Let me know if you need help with a specific example!
Ranjana Admin JanBask Expert
Answered on Apr 23, 2024
To copy a group of files in AWS CLI using wildcards with the aws s3 cp command, follow these steps:
Specify the source path with the wildcard pattern to match the group of files you want to copy.
Provide the destination S3 bucket and optionally specify the destination path.
If the source path includes subdirectories, use the --recursive flag.
Here's an example command:
aws s3 cp s3://source-bucket/path/to/files/* s3://destination-bucket/destination-path/ --recursive
s3://source-bucket/path/to/files/* specifies the source path with the wildcard * to match a group of files in the specified directory.
s3://destination-bucket/destination-path/ specifies the destination S3 bucket and path where the files will be copied.
The --recursive flag is used to copy files recursively if the source path includes subdirectories.
Adjust the source and destination paths according to your requirements. This command will copy all files matching the wildcard pattern from the source bucket to the destination bucket.
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Step-by-step AWS guides from industry experts
Common AWS interview questions, answered
Guides, tips and career advice on AWS from JanBask experts.
AWS How to Become an AWS Certified Solutions Architect
Learn how to become an AWS Solutions Architect with our complete guide. Discover exam requirements, salary potential, and…
AWS AWS Solution Architect Salary in 2025 by Location, Skills, and Experience
The AWS Solution Architect Salary varies as per location, job role, skills, and more. Read this blog to learn how much an AWS…
AWS AWS Certification Cost, Courses, Exam Details, Path & Salary : The Comprehensive Guide
How Much Does AWS Certification Cost In 2025- Get aws certification price, types, and AWS certification course fees for your…
AWS Why AWS Training Certification is a Game-Changer for Your Career in 2025
Discover why AWS training certification is crucial in 2025. Learn how it boosts career opportunities, skills, and salary…