AWS S3 Sync Not Deleting Files? How --delete, --exclude and Timestamps Really Work (and Why Changed Files Get Skipped)
aws s3 sync never deletes anything unless you add --delete. By default it only copies files that are new or changed, so a file you renamed or removed on your computer stays in your S3 bucket forever. Add --delete and sync removes destination files that no longer exist at the source, except files matched by an --exclude filter, which are protected from deletion on purpose. Always run it once with --dryrun first, and check the direction, because --delete deletes from whichever side you put second. Here is the surprise that catches careful people: sync doesn't compare file contents at all. It looks only at size and timestamp. So when a file in S3 changes but keeps the same size, a download sync can skip it entirely, and a changed file you upload with an old timestamp never goes up. In the example on this page, a price that went from $49 to $59 in S3 stayed at $49 on the shop's laptop, and sync printed nothing at all.
Jake runs a phone repair shop. His website and his price list live in S3, and his friend Ethan, a developer, set up two small commands to keep them current: one that pushes the website folder from Jake's laptop to S3, and one that pulls the price list down to the laptop in Jake's second shop every morning. It worked for months. Then Jake renamed his "Repairs" page to "Services," ran the usual command, and the old page was still online. He added --delete, ran it, and it worked. Feeling confident, he ran the same command the other way round to "get the latest from S3," and his unpublished holiday-hours page vanished from his laptop. A week later the second shop was still quoting last month's screen price. This page is what Ethan walked him through: how sync decides what to copy, why it isn't deleting, how to use --delete without losing work, how --exclude and --include really match, why changed files get skipped, when sync overwrites a newer file, and how it compares with aws s3 cp.
New to S3? Our plain-English guide to Amazon S3 explains buckets, objects and keys in about ten minutes. You can follow this page without it; every step starts from zero.
How aws s3 sync works: the three questions it asks every file
The aws s3 sync command copies a whole folder in one direction: from your computer to S3, from S3 to your computer, or from one bucket or prefix to another. You give it a source and a destination, and it works out what's different. That's the whole appeal over a plain copy: run it twice and the second run does almost nothing, because everything already matches.
To work out what's different, sync lists both sides and asks three questions about every file, in this order:
- Is it missing at the destination? Then copy it.
- Is the size different? Then copy it, whatever the timestamps say.
- Is the source newer than the destination? For uploads and bucket-to-bucket copies, copy it. For downloads, the rule is different, and that difference is the most expensive surprise on this page.
Two things are missing from that list. Sync never opens a file to compare what's inside, so two files with the same size and an acceptable timestamp count as identical even if every byte differs. And sync never deletes anything, unless you add --delete. Those two facts explain almost every "aws s3 sync isn't working" complaint.
Here is the first sync of Jake's website folder, a small folder named site pushed to a bucket named jakes-shop-site:
aws s3 sync site s3://jakes-shop-site
upload: site/css/main.css to s3://jakes-shop-site/css/main.css
upload: site/index.html to s3://jakes-shop-site/index.html
upload: site/debug.log to s3://jakes-shop-site/debug.log
upload: site/repairs.html to s3://jakes-shop-site/repairs.html
Sync is recursive by default, so subfolders like css come along without any extra flag. And S3 has no real folders, only object names with slashes in them, so an empty folder on your computer never shows up in the bucket. A folder appears in S3 only once it holds at least one file.
Jake: "So it's like a mirror."
Ethan: "It's more like a delivery driver with a checklist. He brings over anything new and anything that looks different on the label. He never takes anything away unless you hand him a second list that says 'remove these,' and he never opens the boxes to check what's inside."
Why aws s3 sync is not deleting files: the six causes
When a file you removed or renamed is still sitting in S3 after a sync, one of these six things is happening. They're in order of how often they cause the problem.
1. You didn't add --delete
This is the cause for most people, and it isn't a bug: by default sync only adds and updates. Here is what happened when Jake renamed repairs.html to services.html and synced again:
aws s3 sync site s3://jakes-shop-site
upload: site/services.html to s3://jakes-shop-site/services.html
One upload, no delete. The bucket now holds both pages, and the old one is still live on his website. Adding --delete tells sync to remove anything at the destination that doesn't exist at the source:
aws s3 sync site s3://jakes-shop-site --delete
delete: s3://jakes-shop-site/repairs.html
2. The file matches one of your --exclude patterns
Filters work in both directions. A file you exclude is left out of the copy, and it's also left out of the delete. If your command has --exclude "*.log" and you delete debug.log on your computer, --delete still won't remove debug.log from the bucket. That protects things like log folders or uploads that other tools write into the same prefix. If you really want those files gone, remove the pattern for one run, or delete them with aws s3 rm.
3. The bucket has versioning turned on
In a versioned bucket, --delete works, but S3 doesn't really erase anything. It adds a "delete marker," a placeholder that hides the file, and keeps every earlier version underneath it. The file disappears from aws s3 ls and from the console's normal view, then reappears the moment you switch on "Show versions." You also keep paying for the hidden versions until a lifecycle rule or a manual cleanup removes them. Here is what the versions look like after a --delete removed b.txt from a versioned bucket:
aws s3api list-object-versions --bucket jakes-shop-site --prefix b.txt --query '{Versions:Versions[].{K:Key,Latest:IsLatest},DeleteMarkers:DeleteMarkers[].{K:Key,Latest:IsLatest}}'
{
"Versions": [
{
"K": "b.txt",
"Latest": false
}
],
"DeleteMarkers": [
{
"K": "b.txt",
"Latest": true
}
]
}
That's sync working correctly. Our guide to hidden versions in S3 shows how to clear old versions when you want them gone for good.
4. You're syncing to a different prefix than you think
Sync only looks inside the exact prefix you name. aws s3 sync site s3://jakes-shop-site/website --delete compares your folder with the objects under website/, and leaves everything else in the bucket alone, including a neighboring website-old/ prefix or a website.txt object at the top. With or without a trailing slash, sync treats the S3 side as a folder. If the stale file lives at the top of the bucket and you synced into a subfolder, or the other way round, --delete will never reach it.
5. The deleted file is still being served from a cache
If your bucket sits behind CloudFront, the object can be gone from S3 while CloudFront keeps serving its cached copy for hours. Check with aws s3 ls: if the file isn't listed, sync did its job, and what you need is a CloudFront invalidation. Our guide to CloudFront not updating walks through it.
6. You ran sync in the other direction
--delete only ever deletes from the destination, the second path in the command. If you meant to clean up the bucket but put the bucket first, sync tried to delete from your computer instead, and the bucket was never touched. The next section is about exactly this, because the reverse mistake loses work.
Using --delete safely: dry run, direction, and the empty-folder wipe
--delete is the most useful flag sync has and the only one that can cost you files. The routine below takes ten seconds and prevents every disaster on this page.
- Read the command right to left. The last path is the one that gets changed.
aws s3 sync site s3://jakes-shop-site --deletechanges the bucket.aws s3 sync s3://jakes-shop-site site --deletechanges your laptop. - Run it with
--dryrunfirst. Sync prints exactly what it would do, with(dryrun)in front of every line, and changes nothing. - Read every
delete:line. If any of them surprises you, stop and find out why before you run it for real. - Run the same command again without
--dryrun. Use the up-arrow so nothing else changes.
Here is the dry run Jake should have done before he ran the command the other way round. He had a new, unpublished page on his laptop, holiday-hours.html, that wasn't in S3 yet:
aws s3 sync s3://jakes-shop-site site --delete --dryrun
(dryrun) delete: site/holiday-hours.html
That one line would have saved his draft. Without --dryrun, sync deletes the file from his laptop, not to the trash, just gone, because from S3's point of view a file that exists only on the laptop is an extra.
Jake: "I thought sync meant both sides end up with everything."
Ethan: "That's the word's fault. aws s3 sync is one-way. The first path is the truth, and the second path is made to look like it. With --delete, 'look like it' includes throwing things out."
An empty or wrong source folder wipes the destination
Sync checks that the source exists. A typo is caught before anything happens:
aws s3 sync ./sitte s3://jakes-shop-site --delete
aws: [ERROR]: The user-provided path ./sitte does not exist.
It exits with code 255 and touches nothing. But a source folder that exists and happens to be empty is perfectly valid, and with --delete it means "make the bucket empty too." That's how build scripts wipe live websites: the build step fails quietly, leaves an empty dist folder, and the deploy step syncs it with --delete. In a deploy script, check that the folder has files before syncing, for example with test -n "$(ls -A dist)" on Linux and macOS, and stop the script if it doesn't.
Here is how each form of the command behaves, all with --delete:
| Command | What can be deleted | From where |
|---|---|---|
aws s3 sync site s3://jakes-shop-site --delete | Objects in the bucket with no matching local file | The bucket |
aws s3 sync s3://jakes-shop-site site --delete | Local files with no matching object | Your computer |
aws s3 sync s3://bucket-a s3://bucket-b --delete | Objects in bucket-b that aren't in bucket-a | bucket-b |
aws s3 sync emptyfolder s3://jakes-shop-site --delete | Everything under that prefix | The bucket |
aws s3 sync site s3://jakes-shop-site --delete --exclude "*.log" | Same as the first row, but never a .log file | The bucket |
One more safety net is worth the two minutes it takes: turn on versioning for any bucket you sync to with --delete. A wrong delete then becomes a delete marker you can remove, instead of a lost file.
--exclude and --include in aws s3 sync: how the filters really match
Filters are where most sync commands go subtly wrong, because they don't behave like the folder patterns you know from other tools. Four rules cover everything:
- Everything is included until a filter says otherwise. An
--includeon its own changes nothing, because nothing was excluded in the first place. - Filters are applied in the order you write them, and the last match wins. To copy only some files, exclude everything first, then include what you want.
- Patterns are relative to the source folder.
--exclude "logs/*"means thelogsfolder inside your source, not alogsfolder anywhere on your disk. *also matches across folders.--exclude "*.log"catcheslogs/app.loganda/b/c/old.log, not just log files at the top level.
Here's what each pattern did on a test folder holding readme.txt, top.log, logs/app.log and img/cat.jpg, all with --dryrun:
| Filters | What sync uploads | Why |
|---|---|---|
--exclude "*.log" | readme.txt, img/cat.jpg | * reaches into logs/ too |
--include "*.jpg" | All four files | Nothing was excluded, so include does nothing |
--exclude "*" --include "*.jpg" | img/cat.jpg | Exclude all, then add back the JPEGs |
--include "*.jpg" --exclude "*" | Nothing | The last filter wins, and it excludes everything |
--exclude "logs/*" | readme.txt, top.log, img/cat.jpg | Only the logs folder is skipped |
--exclude "/logs/*" | All four files | A leading slash matches nothing |
Always put the pattern in quotes. Without them, your shell expands *.log into the names of matching files in your current folder before the AWS CLI ever sees it, and the filter quietly becomes something else.
So "copy only the images" is written like this:
aws s3 sync site s3://jakes-shop-site --exclude "*" --include "*.jpg" --include "*.png"
And "everything except the logs and the drafts folder" like this:
aws s3 sync site s3://jakes-shop-site --delete --exclude "*.log" --exclude "drafts/*"
Remember the deletion rule from earlier: with --delete, those excluded files and folders are also safe from deletion at the destination.
Jake: "So I can't just say 'only photos'?"
Ethan: "You can, in two steps. First 'nothing,' then 'except photos.' Sync starts every file at 'yes,' and the last rule that matches decides."
Why aws s3 sync is not uploading changed files: the timestamp rule
Remember the three questions. For an upload, a file that exists on both sides with the same size is copied only if your local copy is newer than the object in S3. S3's "last modified" time is the moment the object was uploaded, so in normal editing this just works: you save a file, its timestamp becomes "now," and sync uploads it.
It breaks when a changed file keeps its size and carries an old timestamp. That happens more often than you'd think:
- Files extracted from a zip or tar archive keep the timestamps stored in the archive.
cp -p,rsync -tand many backup-restore tools preserve original timestamps.- Some build tools and generators write files with a fixed timestamp so builds are reproducible.
- A one-character fix, such as a price from 49 to 59 or a typo in a config value, keeps the file the same size.
Here is a file uploaded with the content AAAA, then changed to BBBB (same size) with its timestamp set back to 2020, the way an archive would leave it. Every variation of sync skipped it:
aws s3 sync up s3://jakes-shop-site/d
aws s3 sync up s3://jakes-shop-site/d --exact-timestamps
aws s3 sync up s3://jakes-shop-site/d --size-only
All three printed nothing, and the object in S3 still said AAAA. --exact-timestamps doesn't help here, because it changes only how downloads compare times; for uploads, sync still asks "is the local file newer?" And --size-only makes things worse by design: it ignores timestamps completely.
Two reliable fixes:
- Give the file a fresh timestamp.
touch up/price.txton Linux or macOS, then sync again; it uploads. After extracting an archive,find site -type f -exec touch {} +refreshes every file at once. - Use
aws s3 cpfor files you know changed.cpdoesn't compare anything; it always uploads and replaces the object.
aws s3 cp up/price.txt s3://jakes-shop-site/d/price.txt
The download trap: a changed S3 file with the same size is skipped
This is the one that cost Jake money. When you sync from S3 to your computer, sync sets each downloaded file's local timestamp to the object's "last modified" time in S3. So right after a download, the two match exactly:
stat -c '%y' shop2/price-list.csv
aws s3api head-object --bucket jakes-shop-prices --key price-list.csv --query LastModified --output text
2026-10-11 11:52:46.000000000 +0000
2026-10-11T11:52:46+00:00
Now Ethan changes the screen price in the price list from 49 to 59 and uploads it. Same number of characters, so the file is the same size, and the object in S3 is now newer than the shop's copy. You'd expect the next morning's sync to fetch it. It doesn't:
aws s3 sync s3://jakes-shop-prices shop2
cat shop2/price-list.csv
screen,49
battery,39
No output from sync, no error, and the shop is still quoting $49. For downloads, the default rule is to skip a same-size file unless the local copy is newer than the S3 version, the opposite of what most people assume. The fix is one flag:
aws s3 sync s3://jakes-shop-prices shop2 --exact-timestamps
download: s3://jakes-shop-prices/price-list.csv to shop2/price-list.csv
With --exact-timestamps, a same-size file is skipped only when the two timestamps match exactly, so any change in S3 comes down. For anything you pull on a schedule, such as price lists, configuration files or data feeds, add it to the command and forget about it.
Jake: "Three days of wrong quotes because two numbers have the same number of digits."
Ethan: "Because sync never reads the file. It looks at the label: size and date. Same size, and the date rule for downloads says 'leave it.' --exact-timestamps makes it compare the date exactly, and any edit changes the date."
Does aws s3 sync overwrite files? Yes, even newer ones
People often assume sync works on "newest wins." It doesn't. The size check comes before the time check, so a different size means "copy," whichever side is newer. Here, bucket A holds an older, shorter version of a file, and bucket B holds a newer edit that's longer:
aws s3 sync s3://jakes-shop-a s3://jakes-shop-b
copy: s3://jakes-shop-a/r.txt to s3://jakes-shop-b/r.txt
The newer edit in bucket B is gone, replaced by the older file from A. If the destination might hold newer work you want to keep, you have two options:
--no-overwritecopies only files that don't exist at the destination yet, and never replaces anything. It works onaws s3 cptoo.- Turn on versioning at the destination, so an overwritten object keeps its earlier versions and you can bring one back.
The reverse is also true. aws s3 cp always overwrites, even when your local file is older than the object in S3. Only --no-overwrite stops it.
aws s3 sync in CI/CD: why every deploy re-uploads everything
A build server usually checks out your code fresh for every run, which gives every file a brand-new timestamp. Every file is now "newer" than its copy in S3, so sync uploads the whole site on every deploy, even when nothing changed. Touch a file without changing a byte and sync uploads it again; add --size-only and it's skipped.
aws s3 sync dist s3://jakes-shop-site --delete --size-only
--size-only compares sizes and nothing else. It's a fair trade for sites where most changes alter the size, and a risky one for small edits that don't, as the price list showed. Two habits make it safe enough:
- Build files whose names change when their content changes, such as
main.3f9a2c.css; most front-end build tools do this. A changed file is then a new file, and size never matters. - Upload the few files that keep their names, usually
index.html, withaws s3 cpafter the sync, so they always go up.
Re-uploading everything isn't free either. Each upload is a PUT request, and each sync lists both sides before it copies anything. For a small site that's pennies, but for buckets with millions of objects the listing alone adds up; our guide to S3 request pricing has the numbers.
aws s3 sync vs cp: which one to use
Both commands move files between your computer and S3. The difference is whether they think first.
| Question | aws s3 sync | aws s3 cp |
|---|---|---|
| Single file? | No, folders and prefixes only | Yes |
| Whole folder? | Yes, recursive by default | Only with --recursive |
| Skips unchanged files? | Yes, by size and timestamp | No, copies everything every time |
| Overwrites existing files? | When size differs or source is newer | Always |
| Can delete extras? | Yes, with --delete | No |
| Never replace existing files | --no-overwrite | --no-overwrite |
| Best for | Keeping a folder and a prefix matched, again and again | One-off copies, single files, and forcing an upload |
Point sync at a single file and it treats the name as a folder: aws s3 sync site/index.html s3://jakes-shop-site prints warning: Skipping file .../site/index.html/. File does not exist. and exits with code 2. For one file, cp is the tool.
A good rule: use sync for anything you run more than once, and cp when you need to be sure a file goes up no matter what. The download direction works the same way: aws s3 cp s3://jakes-shop-prices/price-list.csv shop2/ always fetches the file, which is another fix for the download trap when it's a single file.
"Skipping file ... Object is of storage class GLACIER": sync and archived objects
If some objects in a prefix have moved to the S3 Glacier Flexible Retrieval (GLACIER) or Glacier Deep Archive (DEEP_ARCHIVE) storage classes, a download or bucket-to-bucket sync can't copy them, and it says so for each one. Objects in Glacier Instant Retrieval download normally.
warning: Skipping file s3://jakes-shop-site/g/cold.txt. Object is of storage class GLACIER. Unable to perform download operations on GLACIER objects. You must restore the object to be able to perform the operation. See aws s3 download help for additional parameter options to ignore or force these transfers.
The other files still download, but the command ends with exit code 2 instead of 0, which fails scripts and CI jobs that check it. You have three choices:
- Restore the objects first with
aws s3api restore-object, wait for the restore to finish, then sync with--force-glacier-transfer. Sync can't see restore status in a folder listing, so without that flag it keeps skipping restored objects too. - Accept that they're archived and add
--ignore-glacier-warnings. The warnings disappear and the exit code goes back to 0; the archived objects are still skipped. - Exclude them with a filter if they all live under one prefix, such as
--exclude "archive/*".
Restores cost money and can take hours. Our guide to Glacier retrieval costs explains the options before you restore a whole prefix.
Making aws s3 sync faster
Sync sends 10 requests at a time by default. For many small files, raising that number is the single biggest speed-up:
aws configure set default.s3.max_concurrent_requests 20
That adds an s3 section to the default profile in your AWS config file:
[default]
s3 =
max_concurrent_requests = 20
Raise it in steps and stop when the speed stops improving. Two other habits help more than people expect:
- Sync the smallest prefix you can. Sync lists both sides every time, so syncing
s3://bucket/site/imagesinstead of the whole bucket can turn minutes of listing into seconds. - Use filters to skip what never changes. An
--exclude "videos/*"on a site whose videos never change saves both the listing comparison and any accidental re-uploads.
If you see "503 Slow Down" errors while syncing large numbers of objects, the bucket is asking for fewer requests per second on that prefix; our S3 503 Slow Down guide covers it.
aws s3 sync examples: the commands you'll actually use
Here are the everyday jobs, each as one command. Every one of them works with --dryrun added, which is the safest way to try a new one.
| Job | Command |
|---|---|
| Upload a folder | aws s3 sync site s3://jakes-shop-site |
| Upload the folder you're in | aws s3 sync . s3://jakes-shop-site |
| Download a bucket or prefix | aws s3 sync s3://jakes-shop-site site |
| Make the bucket an exact mirror | aws s3 sync site s3://jakes-shop-site --delete |
| Preview any of these | add --dryrun |
| Copy one bucket into another | aws s3 sync s3://bucket-a s3://bucket-b |
| Sync just one subfolder | aws s3 sync site/images s3://jakes-shop-site/images |
| Skip your Git history | aws s3 sync site s3://jakes-shop-site --exclude ".git/*" |
| Only photos | aws s3 sync site s3://jakes-shop-site --exclude "*" --include "*.jpg" |
| Cheaper storage for rarely read files | aws s3 sync backups s3://jakes-shop-site/backups --storage-class STANDARD_IA |
| Website cache header | aws s3 sync site s3://jakes-shop-site --cache-control "max-age=300" |
| Quiet output for scripts | add --only-show-errors |
| Never replace existing files | add --no-overwrite |
| Scheduled pull that catches every change | aws s3 sync s3://jakes-shop-prices shop2 --exact-timestamps |
Sync also guesses each file's content type from its extension, so index.html arrives in S3 as text/html and a browser renders it instead of downloading it. Add --no-guess-mime-type only if you set content types some other way.
Flags combine freely. Jake's website push ended up as this one line, run with --dryrun first:
aws s3 sync site s3://jakes-shop-site --delete --exclude ".git/*" --exclude "*.log" --cache-control "max-age=300"
aws s3 sync between accounts
Syncing from a bucket in one AWS account to a bucket in another is the same command as any bucket-to-bucket sync. Sync copies the objects inside S3, so the data never passes through your computer. What changes is permissions, because one set of credentials has to reach both buckets:
- On the source bucket:
s3:ListBucketon the bucket ands3:GetObjecton the objects. - On the destination bucket:
s3:ListBucket,s3:PutObject, ands3:DeleteObjectif you use--delete. - For the bucket in the other account: its bucket policy has to allow your IAM user or role as well, because your own account's IAM policy can't grant access to someone else's bucket. Our guide to S3 cross-account access denied shows both halves.
- If the source objects use a customer managed KMS key, you also need
kms:Decrypton that key. Our guide to S3 KMS.AccessDeniedException covers it.
Who owns the copied objects depends on the destination bucket's Object Ownership setting. New buckets default to "Bucket owner enforced": ACLs are disabled and the bucket owner automatically owns every object, whoever uploaded it, so a cross-account sync needs nothing extra. Older buckets with ACLs enabled can leave the copies owned by your account, and the bucket's owner then gets AccessDenied reading them. For those, add --acl bucket-owner-full-control, which buckets with ACLs disabled also accept. Any other --acl value, such as public-read, fails on a bucket with ACLs disabled with AccessControlListNotSupported; our guide to "The bucket does not allow ACLs" explains the fix.
If the two buckets are in different Regions, add --source-region with the source bucket's Region, and set --region to the destination's.
aws s3 sync on Windows, and on Macs
The command is identical on Windows. Local paths can use backslashes, and filter patterns can use forward slashes: sync converts / in a pattern to the local separator before matching, so --exclude "logs/*" works on every system.
aws s3 sync C:\shop\site s3://jakes-shop-site --delete --exclude "logs/*" --dryrun
Two Windows details catch people:
- Quote patterns with double quotes in Command Prompt. Command Prompt doesn't treat single quotes as quotes, so
--exclude '*.log'passes the quote marks into the pattern and it matches nothing. PowerShell accepts either kind. - Files copied with their original dates, from an extracted zip, a USB drive or a restored backup, hit the same upload rule as on Linux: same size plus an old timestamp means sync skips them.
Windows and macOS share one more trap on downloads. Their file systems treat Photo.jpg and photo.jpg as the same file, while S3 treats them as two different objects. By default sync downloads both, and on those systems one lands on top of the other. Current AWS CLI v2 releases have a --case-conflict option with the values error, warn, skip and ignore (the default); --case-conflict warn at least tells you when it happens.
Still stuck? Troubleshooting aws s3 sync by symptom
Sync prints nothing and exits 0
Sync thinks both sides already match. That's correct if nothing changed, and wrong if a same-size file changed: see the upload rule and the download trap. Run with --dryrun --debug and look for lines containing syncing:. They list every file sync decided to copy, with the reason, such as "file does not exist at destination"; a file missing from that list was judged unchanged.
Sync re-uploads every file every time
Your local timestamps keep changing, usually because of a fresh checkout in CI or a build step that rewrites every file. Use --size-only with content-hashed file names, as in the CI section.
Files I deleted locally are still in S3
Add --delete. If you already did, check whether an --exclude pattern matches the file, whether you synced to the same prefix the file lives under, and whether the bucket is versioned and you're looking at a hidden version.
--delete removed files I wanted
The source didn't have them, or you ran the command in the wrong direction. On a versioned bucket, delete the delete marker to bring an object back. On your computer, the file isn't in the trash; check your backups. Next time, run with --dryrun first.
AccessDenied during sync
Sync needs to list both sides before it copies, so it needs s3:ListBucket on the bucket as well as s3:GetObject or s3:PutObject on the objects, plus s3:DeleteObject when you add --delete. Our guide to S3 Access Denied walks through each cause.
Exit code 2 but everything looks copied
Exit code 2 means at least one file was skipped with a warning, most often a Glacier object or a file sync couldn't read. Look for warning: lines in the output.
aws s3 sync: frequently asked questions
Does aws s3 sync delete files?
Not by default. aws s3 sync only copies new and changed files. Add --delete to remove files at the destination that no longer exist at the source. Files matched by an --exclude filter are never deleted, even with --delete.
How does aws s3 sync work?
It lists the source and the destination, then copies each file that is missing at the destination, has a different size, or is newer at the source. For downloads, a same-size file is copied only if the local copy is newer, unless you add --exact-timestamps. It never compares file contents.
What does aws s3 sync do?
It makes a destination folder or S3 prefix match a source, one way. It copies new and updated files recursively, skips files that look unchanged by size and timestamp, and with --delete removes files that exist only at the destination.
Why is aws s3 sync not deleting files?
Usually because --delete is missing. Other causes: the file matches an --exclude pattern, the bucket is versioned so a delete marker hides the old version, you synced a different prefix, CloudFront still serves a cached copy, or you ran the command in the other direction.
Does aws s3 sync overwrite files?
Yes, when the size differs or the source is newer. A different size wins even when the destination is newer, so sync can replace a newer file with an older one. Add --no-overwrite to copy only files that don't exist at the destination.
Why is aws s3 sync not uploading changed files?
The file kept the same size and has an older timestamp than the object in S3, which happens after extracting archives or restoring backups. Refresh the timestamp with touch, or upload the file with aws s3 cp, which always copies.
Why is aws s3 sync not downloading a changed file?
For downloads, sync skips a same-size file unless the local copy is newer than the S3 object. An edit that keeps the size, like 49 to 59, is skipped. Add --exact-timestamps so any timestamp difference triggers a download.
What is the difference between aws s3 sync and aws s3 cp?
sync compares both sides and copies only new or changed files, works on folders recursively, and can delete extras with --delete. cp copies whatever you name every time, overwrites without comparing, needs --recursive for folders, and never deletes.
How do I exclude files in aws s3 sync?
Add --exclude with a quoted pattern, such as --exclude "*.log" or --exclude "drafts/*". Patterns are relative to the source folder, * also matches inside subfolders, and you can repeat --exclude. Excluded files are also protected from --delete.
Why is aws s3 sync --include not working?
Everything is included by default, so --include alone changes nothing. Exclude everything first and then include what you want, in that order: --exclude "*" --include "*.jpg". Filters apply in order and the last match wins.
What does aws s3 sync --dryrun do?
It prints every upload, download, copy and delete the command would perform, each line starting with (dryrun), without changing anything. Run every --delete command this way first and read the delete lines.
Is aws s3 sync recursive?
Yes. sync always includes every subfolder of the source; there is no --recursive flag for it. Empty folders are not created in S3, because S3 has no real folders, only object names that contain slashes.
What does --exact-timestamps do in aws s3 sync?
When syncing from S3 to your computer, it skips a same-size file only when the timestamps match exactly. Without it, sync skips same-size files unless the local copy is newer, so changes in S3 that keep the size are missed. It has no effect on uploads.
What does --size-only do in aws s3 sync?
It decides what to copy by file size alone and ignores timestamps. It stops CI pipelines from re-uploading every file after a fresh checkout, but it misses edits that keep the size the same, so pair it with content-hashed file names.
Can aws s3 sync two buckets?
Yes: aws s3 sync s3://bucket-a s3://bucket-b copies between buckets without downloading to your computer. Your credentials need read access on the source and write access on the destination, plus delete access if you add --delete.
How do I make aws s3 sync faster?
Raise concurrency with aws configure set default.s3.max_concurrent_requests 20 (the default is 10), sync the smallest prefix you can, and exclude folders that never change. Increase it gradually and stop when the speed stops improving.
Does aws s3 sync delete files in the source?
No. sync never changes the source. --delete removes files only from the destination, the second path in the command. That is why running the command in the wrong direction deletes from the side you meant to copy from.
What does exit code 2 mean for aws s3 sync?
At least one file was skipped with a warning while the rest succeeded, most often an object in a Glacier storage class that hasn't been restored. --ignore-glacier-warnings hides those warnings and returns exit code 0.
For readers preparing for an AWS certification
We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.
Exams that test this topic: Developer – Associate (DVA-C03 from December 1, 2026) • CloudOps Engineer – Associate (SOA-C03).
Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:
1. aws s3 sync copies new files but leaves deleted ones in the bucket. Why?
Sync never deletes by default. Add --delete to remove destination files that no longer exist at the source.
2. How do you see what sync would delete before it does?
Run it with --dryrun; it prints every copy and delete without changing anything.
3. Versioning is on and sync --delete removed files. Are they gone?
No. A delete marker hides the current version, and earlier versions stay restorable until lifecycle rules expire them.
4. How does sync decide which files to copy?
By comparing size and last-modified time. --exact-timestamps or --size-only change that behavior.
5. Huge directory trees sync slowly. What helps?
More parallel requests through the CLI's max_concurrent_requests setting, or AWS DataSync for large and recurring transfers.
6. Which service suits moving hundreds of terabytes from on premises?
AWS DataSync over the network, or AWS Snowball devices when bandwidth is limited.
Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.
Jake's two commands now look a little different. The website push has --delete on the end and runs with --dryrun first every time; he reads the delete lines out loud, which Ethan says is the whole trick. The morning price-list pull has --exact-timestamps, and the second shop quoted $59 the next day. His holiday-hours page is back too, rebuilt from the copy he'd emailed himself. The bucket has versioning turned on now, so the next mistake, if there is one, is a click away from undone. Ethan wrote the line below on a sticky note and stuck it to Jake's monitor.
📌 If you keep one line from this page
aws s3 sync is one-way and reads labels, not contents: the second path gets changed, size and time decide what moves, and nothing is deleted without --delete.
Dry-run every --delete, and add --exact-timestamps to anything you pull on a schedule.
Revision note. Written October 11, 2026, for everyone whose bucket kept a file they deleted, or lost one they didn't. "Look before you leap," says the old proverb; with sync, the look is one flag long: --dryrun.