---
title: "Learn the AWS S3 Copy Command Through Examples"
description: "Discover the different ways to utilize the AWS S3 copy command through practical examples in this ATA Learning tutorial!"
canonical: "https://adamtheautomator.com/aws-s3-copy/"
---

# Learn the AWS S3 Copy Command Through Examples

> Discover the different ways to utilize the AWS S3 copy command through practical examples in this ATA Learning tutorial!

Source: https://adamtheautomator.com/aws-s3-copy/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Learn the AWS S3 Copy Command Through Examples](https://adamtheautomator.com/wp-content/uploads/2022/08/Learn-the-AWS-S3-Copy-Command-Through-Examples.jpg)

# Learn the AWS S3 Copy Command Through Examples

[![](https://secure.gravatar.com/avatar/1bc5e1d52466fc3739f550c8d78be310684747bf1466a98d698320627ea243e2?s=192&d=mm&r=g)Michael Nguyen Tu](https://adamtheautomator.com/author/michael-nguyen-tu/)25 August 20225 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[AWS](/tag/aws/)[AWS S3](/tag/aws-s3/)[Command Line](/tag/command-line/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Copying a File with the AWS S3 Copy Command](#copying-a-file-with-the-aws-s3-copy-command)
*   [Copying Multiple Files to S3 Buckets](#copying-multiple-files-to-s3-buckets)
*   [Copying a Local File to S3 with an Expiration Date](#copying-a-local-file-to-s3-with-an-expiration-date)
*   [Performing a Dry Run of the AWS Copy Command](#performing-a-dry-run-of-the-aws-copy-command)
*   [Suppressing All Output Except Errors](#suppressing-all-output-except-errors)
*   [Conclusion](#conclusion)

As a cloud storage user, you may need to copy files from one location to another, either within the same bucket or across different buckets. Thankfully, the AWS S3 copy command lets you copy files without the hassle.

Not a reader? Watch this related video tutorial!

**_Not seeing the video? Make sure your ad blocker is disabled._**

In this tutorial, you will learn how to use the AWS S3 copy command through practical examples to copy local files to your AWS S3 bucket.

Ready? Read on and add more ways to manage your AWS S3 storage efficiently!

## Prerequisites

This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have the following.

*   An [active AWS account](https://aws.amazon.com/free/).
    
*   An IAM user with the AmazonS3FullAccess permission.
    

Related:[Helpful Guide to IAM in AWS Through Examples](https://adamtheautomator.com/iam-aws/)

*   A local machine with the AWS CLI [installed](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) and [configured](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html) – This tutorial uses Windows 10 and [PowerShell 7](https://adamtheautomator.com/powershell-7-upgrade/).

Related:[How to Walk Through a PowerShell 7 Upgrade](https://adamtheautomator.com/powershell-7-upgrade/)

*   An [AWS bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html) with directories to copy files to and from.

## Copying a File with the AWS S3 Copy Command

The essential task an admin can perform with the AWS S3 service is to upload a single file from their computer or server to an S3 bucket. This task can be achieved with a single `aws s3 cp` command.

The basic syntax for the `aws s3 cp` command is as follows where:

*   `<local/path/to/file>` – is the file path on your local machine to upload.
*   `<s3://bucket-name>` – is the path to your S3 bucket.

```powershell
aws s3 cp <local/path/to/file> <s3://bucket-name>
```

Suppose you plan to copy a single text file to your S3 bucket. If so, the command below will suffice.

Run the command below to upload a text file (_text01.txt_) from your user home folder (_C:\\Users\\Admin\\_) to an S3 bucket named _test-s3-bucket-0001_. The S3:// prefix starts the S3 bucket for the command to work.

> _Note that you can use your own files to copy to and from your S3 buckets or local machine throughout this tutorial._

```powershell
aws s3 cp C:\\Users\\Admin\\text01.txt s3://test-s3-bucket-0001/text01.txt
```

If the upload is successful, you will see a message similar to the one below. This output indicates the file was uploaded to your S3 bucket.

![Uploading a file to the S3 bucket](https://adamtheautomator.com/wp-content/uploads/2022/08/image-359.png)

Uploading a file to the S3 bucket

Now, run the below command to list (ls) the files inside your S3 bucket (_s3://test-s3-bucket-0001/_).

```powershell
aws s3 ls s3://test-s3-bucket-0001/
```

Below, you can verify the file (_**text01.txt**_) you uploaded to your S3 bucket.

![Verifying the uploaded file to the S3 bucket](https://adamtheautomator.com/wp-content/uploads/2022/08/image-360.png)

Verifying the uploaded file to the S3 bucket

Related:[How To Upload Files to S3 with the AWS CLI](https://adamtheautomator.com/upload-file-to-s3/)

## Copying Multiple Files to S3 Buckets

You’ve just uploaded a file to your S3 bucket with just a single command. But most of the time, you’ll have to upload tons of files in one go. Can the aws s3 cp command handle that task? Yes, by appending the –recursive flag.

Run the below command to copy an entire directory (_C:\\Testdata\\_) to your S3 bucket.

When you append the –recursive flag, any files in the specified directory will be copied to your S3 bucket. The structure of the directory will also be maintained in the bucket, which is helpful when you want to copy the contents of an entire directory without specifying each file individually.

```powershell
aws s3 cp C:\\Testdata\\ s3://test-s3-bucket-0001/Testdata --recursive
```

You will see an output like the one below, which shows all files were successfully copied to your S3 bucket.

![Copying multiple files to an S3 bucket](https://adamtheautomator.com/wp-content/uploads/2022/08/image-361.png)

Copying multiple files to an S3 bucket

Now, run the following command to list (ls) all files inside the _Testdata_ directory under your S3 bucket (s3://test-s3-bucket-0001/Testdata/).

```powershell
aws s3 ls s3://test-s3-bucket-0001/Testdata/
```

You will see all the files you copied from your computer in the output below.

![Verifying uploaded files to the S3 bucket from a local directory](https://adamtheautomator.com/wp-content/uploads/2022/08/image-362.png)

Verifying uploaded files to the S3 bucket from a local directory

## Copying a Local File to S3 with an Expiration Date

One of the tasks you might need to perform when using S3 is copying a file from your computer to an S3 bucket and setting an expiration date for the file. An expiration date is often set to a file for security reasons, making certain files accessible only for a certain period.

For instance, if you have a file named _passwords01.txt_ that you only want to be accessible for 30 days from this day (August 1st).

Run the below command to copy a file (_passwords01.txt_) to your S3 bucket (_s3://test-s3-bucket-0001_) with an expiration (–expires 2022-08-30T00:00:00Z).

```powershell
aws s3 cp C:\\Testdata\\passwords01.txt s3://test-s3-bucket-0001/passwords01.txt --expires 2022-08-30T00:00:00Z
```

You will see an output similar to the one below, which shows the file was successfully copied to your S3 bucket with an expiration date of 30 days from this day (August 1st).

After 30 days, this file will no longer be cached and accessible from your S3 bucket.

![Copying a local file to the S3 bucket with an expiration date](https://adamtheautomator.com/wp-content/uploads/2022/08/image-363.png)

Copying a local file to the S3 bucket with an expiration date

> _The aws s3 cp command expects an_ [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) _formatted date string (YYYY-MM-DDTHH:MM:SSZ) to be passed in for the –expiresflag. This format is an international standard for representing dates and times. So if you put an incorrect date format, you will get the below Parameter validation failed error._

![Getting the “Parameter validation failed” error due to incorrect date format](https://adamtheautomator.com/wp-content/uploads/2022/08/image-364.png)

Getting the “Parameter validation failed” error due to incorrect date format

## Performing a Dry Run of the AWS Copy Command

By now, you already know how to copy files and an entire directory to your S3 bucket. But in some cases, you might want to test the `aws s3 cp` command without copying any files. Doing so helps prevent messing things up, especially if you’re copying project files.

This situation is often referred to as a “what-if” scenario, which is helpful when you want to see what will happen when you execute the command.

Run the following command to perform a dry run (–dryrun) of copying files from your _Testdata_ directory to your S3 bucket (_s3://test-s3-bucket-0001_).

```powershell
aws s3 cp C:\\Testdata\\ s3://test-s3-bucket-0001/Testdata --recursive --dryrun
```

Below, you can see a list of files that would have been copied to your S3 bucket.

![Performing a dry run of copying local files to an S3 bucket](https://adamtheautomator.com/wp-content/uploads/2022/08/image-365.png)

Performing a dry run of copying local files to an S3 bucket

## Suppressing All Output Except Errors

Perhaps you only want to see the generated errors when copying files to your S3 bucket instead of seeing an output of files you copied to your S3 bucket. If so, appending the `--only-show-errors` flag will do the trick.

The –only-show-errors flag comes in handy in debugging your command in case something goes wrong.

Run the below command to copy all files from your local _C:\\Testdata_ directory to your S3 bucket (_s3://test-s3-bucket-0001_) in the directory called _Testdata03_.

```powershell
aws s3 cp C:\\Testdata\\ s3://test-s3-bucket-0001/Testdata03 --recursive --only-show-errors
```

None of the successful file copy outputs that are normally displayed on the output below are shown. Instead, only a blank screen is displayed since this command generated no errors.

![Suppressing outputs other than errors (no error)](https://adamtheautomator.com/wp-content/uploads/2022/08/image-366.png)

Suppressing outputs other than errors (no error)

Now, rerun the same command with a non-existed local path (_C:\\non-existed_) to replicate an error.

```powershell
C:\\Users\\Admin> aws s3 cp C:\\non-existed s3://test-s3-bucket-0001/Testdata03 --recursive --only-show-errors
```

This time, you’ll see an error output similar to the one below since the _C:\\non-existed_ directory doesn’t exist.

![Suppressing outputs other than errors (with error)](https://adamtheautomator.com/wp-content/uploads/2022/08/image-367.png)

Suppressing outputs other than errors (with error)

## Conclusion

You’ve seen that the AWS S3 copy command is useful in copying files from one place to another, specifically from a local directory to an AWS S3 bucket. And in this tutorial, you’ve learned to copy single and multiple files (entire directory), but there are more ways to [customize the file copy process](https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html) as needed.

At this point, you can already manage your AWS S3 storage efficiently and effectively. So why not try these commands out in your own environment? You can even try to use [AWS KMS](https://catalog.us-east-1.prod.workshops.aws/workshops/aad9ff1e-b607-45bc-893f-121ea5224f24/en-US/s3/serverside/ssekms) to secure your S3 files while copying them.

Related:[Use Encryption Keys Like a Pro With AWS Key Management](https://adamtheautomator.com/aws-key-management/)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Faws-s3-copy%2F&text=Learn%20the%20AWS%20S3%20Copy%20Command%20Through%20Examples)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Faws-s3-copy%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Faws-s3-copy%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2023/02/install-aws-cli-mac.jpg)

### [Streamline Your AWS Management with the AWS CLI Mac Client](/aws-cli-mac/)

Take control of your AWS environment and streamline management through the use of the AWS CLI Mac client in this ATA Learning tutorial!

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Getting-Started-with-Amazon-S3-Inventory.jpg)

### [Getting Started with Amazon S3 Inventory](/s3-inventory/)

Learn how to find and retrieve an overview of all your Amazon S3 data with the Amazon S3 Inventory tool in this ATA Learning tutorial!

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26989-monitor-windows-servers-prometheus-grafana-codex.webp)

### [How to Monitor Windows Servers with Prometheus and Grafana](/monitor-windows-servers-prometheus-grafana/)

Set up Windows Server monitoring with windows\_exporter, Prometheus, Grafana, and Alertmanager. Learn how to secure port 9182, scrape targets, and validate alerts.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
