An object bucket has no folders. Yet the AWS console, the <code>aws</code> CLI, rclone and s3cmd all show folders, and some of them will create, copy or delete an empty one. The trick is a zero-byte object whose key ends in a slash, such as <code>photos/</code>. We seeded one bucket with five of these markers and three real files, then ran each tool against it. The same eight keys looked like 8 objects, 3 objects or 10 entries depending on who asked.
What a folder marker is
A marker is an ordinary object: a PUT with an empty body to a key that ends in <code>/</code>. A key like <code>photos/2024/a.jpg</code> already makes <code>photos/</code> and <code>photos/2024/</code> show up as folders whenever you list with a delimiter, so a marker is only needed to make an <em>empty</em> folder visible. The console button "Create folder" does exactly this PUT, which is why people end up with them. Our seed, with the AWS CLI:
The bucket now holds 8 keys: <code>empty/</code>, <code>empty/sub/</code>, <code>empty/sub/deeper/</code>, <code>photos/</code> and <code>photos/2024/</code> at 0 bytes, plus the three 100-byte files. The <code>empty/</code> tree has no real file anywhere in it; <code>photos/</code> and <code>docs/</code> do.
Listing: one bucket, several answers
| Command | What it reported | Counts the markers? |
|---|---|---|
list-objects-v2, no delimiter | 8 keys, 5 of them size 0 | yes, as objects |
list-objects-v2 --delimiter / at the root | 0 objects and 3 common prefixes (docs/, empty/, photos/) | folded into prefixes |
same, --prefix empty/ | 1 object (empty/ itself) and 1 prefix (empty/sub/) | the marker of the folder you are inside comes back as an object |
aws s3 ls s3://bucket/empty/ | PRE sub/ plus a 0-byte line with an empty name | shown as a nameless row |
aws s3 ls --recursive | 8 lines | yes |
rclone lsf -R | 10 entries: 3 files, 7 directories | markers become directories; docs/ and docs/guide/ are made up from the file keys |
rclone size | 3 objects, 300 B | no, skipped |
rclone ls | 3 files | no |
rclone tree | 7 directories, 3 files, empty/sub/deeper included | as directories |
s3cmd ls --recursive | 8 lines, the markers flagged DIROBJ | yes |
The count that matters for billing and for any script that loops over keys is the first row: 8, not 3. <code>rclone size</code> reporting "Total objects: 3" for a bucket that holds 8 keys is not a bug; it counts files. A reconciliation against a manifest (see <a href="https://tport.space/articles/reconcile-bucket-against-manifest-100000-keys-sorted-merge-hash-set-measured">reconciling a bucket against a manifest</a>) that uses rclone on one side and a raw listing on the other will be off by exactly the number of markers.
To find them in your own bucket, ask for zero-byte keys ending in a slash:
Download: which tool recreates the empty folders
We synced the whole bucket into a fresh local folder with each tool. The real files always arrived. The question is the folders that hold no file:
| Download command | Folders created | empty/ tree (3 marker-only folders) present? |
|---|---|---|
aws s3 sync s3://bucket/ dir/ | 4: docs, docs/guide, photos, photos/2024 | no |
rclone copy remote:bucket dir | 4, same | no |
rclone copy --create-empty-src-dirs remote:bucket dir | 7 | yes: empty, empty/sub, empty/sub/deeper |
s3cmd get --recursive s3://bucket/ . | 7 | yes |
So the same bucket becomes two different local trees depending on the command. A backup restored with <code>aws s3 sync</code> silently drops the empty folders that an application may expect to exist (an <code>uploads/</code> or <code>cache/</code> directory, say). The cure is either a tool that keeps them, or code that creates the directories it needs.
Upload: markers are not made unless you ask
We built a local tree with 2 files and 6 directories (<code>a</code>, <code>a/b</code>, <code>c</code>, <code>emptyonly</code>, <code>emptyonly/inner</code> and <code>full</code>; only <code>a/b</code> and <code>full</code> hold a file) and uploaded it into a separate prefix with each tool.
| Upload command | Keys in the bucket | Markers made |
|---|---|---|
aws s3 sync up s3://bucket/up1/ | 2 | 0 |
rclone copy up remote:bucket/up2 | 2 | 0 |
rclone copy --create-empty-src-dirs up ... | 2 | 0 (the flag alone does nothing on a bucket) |
rclone copy --create-empty-src-dirs --s3-directory-markers up ... | 8 | 6 (a/, a/b/, c/, emptyonly/, emptyonly/inner/, full/) |
s3cmd sync up/ s3://bucket/up5/ | 2 | 0 |
Only rclone with <code>--s3-directory-markers</code> writes markers. Note that it also writes them for folders that are not empty (<code>a/</code>, <code>full/</code>), so the key count of a marker-aware copy is higher than the count of the source files.
<code>rclone mkdir</code> behaves the same way. Without the flag it prints "running mkdir on a remote which can't have empty directories does nothing" and the bucket stays empty. With <code>--s3-directory-markers</code>, <code>rclone mkdir remote:bucket/mk2/inner</code> created exactly one key, <code>mk2/inner/</code>; the parent <code>mk2/</code> was not made. The marker came back as 0 bytes with content type <code>application/octet-stream</code>. And <code>aws s3 cp</code> cannot make one at all: copying a zero-byte local file to <code>s3://bucket/zdir/</code> created <code>zdir/zero</code>, because <code>cp</code> treats a trailing slash as a destination folder. Use <code>s3api put-object</code>.
Delete: files alone leave the ghosts behind
Most of the trouble starts here. A marker is its own object, so it only goes when something deletes it by name.
| Action | Keys before | Keys after | What is left |
|---|---|---|---|
aws s3 rm s3://bucket/photos/2024/a.jpg (the only file) | 3 under photos/ | 2 | photos/2024/ and photos/; rclone lsd still lists 2024 |
aws s3 rm --recursive s3://bucket/empty/ | 3 | 0 | nothing: the prefix match includes the markers |
rclone delete remote:bucket/up4 | 8 | 6 | the 6 markers: delete removes files only |
rclone rmdirs remote:bucket/up4 (no flag) | 6 | 6 | all 6, and no error |
rclone rmdirs --s3-directory-markers remote:bucket/up4 | 6 | 0 | nothing |
rclone purge remote:bucket/up3 | 2 files, no markers | 0 | nothing |
rclone rmdir --s3-directory-markers remote:bucket/photos/2024 | 2 | 1 | photos/: only the leaf marker goes |
s3cmd del --recursive s3://bucket/docs/ | 2 files (no markers there) | 0 | nothing |
Two of these are traps. Removing the last file from a folder with a single <code>rm</code> leaves a folder that still shows up in the console and in <code>rclone lsd</code>, with nothing in it. And <code>rclone rmdirs</code> without the flag succeeds, exits normally and removes nothing, because without the flag rclone treats the bucket as one that cannot have empty directories. If you made your markers with rclone, remove them with rclone and the same flag.
We also ran <code>rclone sync --create-empty-src-dirs --s3-directory-markers</code> from a local folder holding one empty directory <code>x</code> onto a prefix that held a marker <code>mk2/inner/</code>. Afterwards only <code>mk2/x/</code> existed: <code>sync</code> deleted the destination marker the way it deletes any extra object (the delete rules are in <a href="https://tport.space/articles/rclone-sync-vs-copy-deleted-files-dry-run-tested">rclone sync or copy: what each one deletes</a>).
What to do
- Treat prefixes as the folders. Write code that does not need an empty folder to exist: create the local directory when you write into it, and never read "the folder is there" as "something was uploaded".
- Pick one convention per bucket. If a tool must keep empty folders through a copy, use rclone with
--s3-directory-markerson every command that reads, writes and removes in that bucket, and say so in the runbook. - Delete whole prefixes.
aws s3 rm --recursiveandrclone purgeremoved markers and files together in our runs; per-file deletes did not. - Count keys, not files, when you compare listings, and filter the zero-byte slash keys first if you want only files (the query above).
- Restore tests should compare folders too if the application needs them: after an
aws s3 syncrestore theempty/tree did not exist.
Related: <a href="https://tport.space/articles/object-storage-key-design-prefixes">designing object-storage keys that stay searchable at 10,000 files</a>.
S3-compatible buckets with no egress fees. Works with the AWS CLI, rclone and s3cmd; create a bucket and an access key in the console.
Explore tport.spaceTest record and sources
- Run 2026-11-20 on Ubuntu 24.04 (Linux 6.8, ext4 local folders) against a private tport.space bucket, region us, endpoint s3.tport.space, from a server in Germany. A new bucket and one read-write key were made for the run; the bucket was emptied and the key revoked afterwards.
- Clients: aws-cli 1.46.3 (botocore 1.43.62), rclone v1.76.0 with
no_check_bucketandupload_cutoff 64M, s3cmd 2.4.0. Other versions may differ; rclone's directory-marker behaviour sits behind its own flag and has changed between releases. - All counts are from our own listings (
list-objects-v2and the tools' listings); every file was 100 random bytes. - Not tested: the tport.space console file browser, the AWS console, macOS or Windows folders, and other tools such as s3fs or Cyberduck.
- Concept: the AWS documentation page "Organizing objects in the Amazon S3 console by using folders" describes the zero-byte slash object; the behaviour of each client above is from our run, not from documentation.