AWS

How Can I Use Wildcards to `cp` a Group of Files With AWS CLI

Wildcards are the special characters used in the AWS CLI commands that allow the user to create specific patterns in their commands. The cp command is used to copy the files from the local directory to the cloud and vice versa.

This guide will explain how to use wildcards to “cp” a group file with AWS CLI.

How Can I Use Wildcards to `cp` a Group of Files With AWS CLI?

Open the “Terminal” from the local system:

Check whether the AWS CLI is installed on the system by using the following command:

aws --version

Executing the above command displays the “aws-cli/2.11.0” installed version of AWS CLI:

Configure the AWS using the IAM credentials:

aws configure

Click here to learn how to configure AWS CLI.

Locate the directory in which the group of files is placed from the local computer:

Head into the folder and find a group of files:

Use the following AWS CLI command to upload the files on the S3 bucket:

aws s3 cp /Users/Lenovo/AWS/File s3://fdxrdfgkhj/prefix/ --recursive --exclude "myapp.html" --include "file-prefix*"

The above command copies the files from the local directory and uploads them to the S3 bucket. The wildcard here is that it does not copy the “myapp.html” file:

Visit the S3 dashboard and click on the “Buckets” page:

Click on the bucket name to open it:

Head inside the “prefix/” folder:

All the files have been copied to the S3 bucket except “myapp.html” which was excluded using a wildcard:

Head back to the buckets page and click on the “Empty” button:

Type “permanently delete” to confirm the deletion of all the objects and then click on the “Empty” button:

After emptying the bucket, click on the “Exit” button:

Use the following command to use the include wildcard:

aws s3 cp /Users/Lenovo/AWS/File s3://fdxrdfgkhj/ --recursive --exclude "*" --include "myapp.html"

The above command has excluded everything by adding a “*” to it and just including only “myapp.html” file:

The bucket only contains the “myapp.html” file and others files have been excluded:

This guide has explained how to use wildcards to ‘cp’ a group of files with AWS CLI.

Conclusion

To use wildcards to copy a group of files with AWS CLI, it is required to install AWS CLI and then configure it using the IAM credentials. Locate the directory from the local system from where the files will be copied and pasted to the AWS cloud. Use the AWS CLI with wildcards to exclude or include the selected files from the pile. This guide has explained how to use wildcards to ‘cp’ a group of files with AWS CLI.

About the author

Talha Mahmood

As a technical author, I am eager to learn about writing and technology. I have a degree in computer science which gives me a deep understanding of technical concepts and the ability to communicate them to a variety of audiences effectively.