Skip to Content

AWS S3 Sync With Delete | 6 Simple Tips

Sharing is caring!

We strive to provide you with authoritative, trustworthy, and expert advice. In doing so, the staff at performs extensive research, editing, and fact checking to every post on this webiste. If you feel that this article can improve, please feel free to reach us at

Before continuing this article, I wanted to let you know that I have a Youtube Channel where I showcase all sorts of video content related to Tech. Subscribing would mean a lot to me, and I very much appreicate all the support!

The AWS S3 Sync with the delete command will sync contents located in a source bucket and target local directory and delete everything else that is not ‘in sync’.

What does the AWS s3 sync with delete command do?

AWS notates that the sync command will “Recursively [copy]  new and updated files from the source directory to the destination” [1]. 

 In other words, the sync command copies files to a destination.

When using the —delete command, everything that is not in the source will be deleted in the destination. 

When to use AWS s3 sync with the delete command

Since the —delete command is an explicit expression, users will generally use it when they want both the source and target destinations to have exact contents.

Anything that the source doesn’t originally have will be deleted in the target destination.

AWS S3 Sync Delete Example

A good example of using the s3 sync delete command would be when you’re trying to sync to directories, while also deleting everything in the target directory that is not currently present in the source directory.

To make it a little more clear, let’s assume someone is trying to sync their AWS S3 bucket to a local directory. 

The local directory has two text files – file.txt and file2.txt. The AWS S3 bucket <s3bucketname>  has contents file3.txt.

Running the s3 sync delete command:

aws s3 sync . s3://<s3bucketname> --delete

Will produce the following:

upload: file.txt to s3://<s3bucketname>/test.txt
upload: file2.txt to s3://<s3bucketname>/test2.txt
delete: s3://<s3bucketname>/file3.txt

Notice how the local directory is the source and the AWS S3 bucket is the destination.  

Since the AWS S3 bucket has different contents originally than the local directory (source), the file3.txt is deleted!

Does AWS S3 sync delete files?

The AWS S3 Sync command does not delete files, but rather copies any new or modified files between a source and target destination.

Files can be deleted by using the —delete command in conjunction with the AWS S3 sync command.

What does S3 Sync Do?

The AWS S3 Sync command simply copies files from a source to a destination, effectively syncing the two directories. 

It also comes with a variety of Boolean expressions that can be used, such as the AWS s3 sync —delete command.

For more information, check out the source content at the bottom of this article.

Does AWS S3 sync Overwrite?

The AWS S3 sync command simply synchronizes contents between a source and destination. This can also apply between two buckets. 

Furthermore, use the —delete command to sync everything between the two directories and delete everything in the target destination that is not in the source [1].

Another AWS S3 Sync CLI example is as follows:

$ aws s3 sync <source> <target> [--options]

Source Content: