Skip to content

Add "aws s3 tree" command for hierarchical listing (like Unix tree) #10839

Open

Description

@joseribon

Describe the feature

Add a new high-level command, aws s3 tree, that prints the contents of a bucket or prefix as an indented tree, modeled on the Unix tree utility (https://github.com/Old-Man-Programmer/tree).

Example:

$ aws s3 tree s3://my-bucket/data/ -L 2
s3://my-bucket/data/
├── 2025/
│   ├── january/
│   └── february/
├── 2026/
│   └── march/
└── manifest.json

5 directories, 1 file

Use Case

Today the only way to see what's in a bucket is aws s3 ls, which shows one level at a time, or aws s3 ls --recursive, which prints every key in one flat list. For large buckets the flat list is often thousands of lines and hard to read, and there is no way to cap the depth. People work around this by piping ls --recursive through awk/sed, mounting the bucket with Mountpoint or s3fs and running tree, or installing rclone just for rclone tree.

A built-in tree command would make it easy to understand a bucket's layout, check that data landed under the right prefixes, and document structure for teammates, without extra tools.

Related: #2683 asked for --max-depth on aws s3 ls. It was closed in 2017, but people kept commenting on it until late 2024, so the need is still there.

Proposed Solution

Add aws s3 tree <S3Uri> alongside the existing high-level aws s3 commands, supporting a subset of Unix tree options:

  • -L, --level <n>: maximum depth to show
  • -d: show only prefixes ("directories")
  • -s / -h / --si: show object sizes, raw or human-readable
  • --du: show cumulative size for each prefix
  • -P <pattern> / -I <pattern>: include / exclude keys matching a pattern (or reuse the existing --include / --exclude semantics)
  • --dirsfirst: list prefixes before objects
  • --noreport: omit the final "N directories, M files" summary
  • -J: JSON output for scripting

Implementation note: when -L is given, the command can walk the bucket level by level using ListObjectsV2 with Delimiter="/", listing only the prefixes it needs. Keys below the depth limit are never listed, so this is much faster on large buckets than listing everything and filtering on the client. This answers the concern raised in #2683 that a depth limit would just throw away results after they're downloaded. Without -L, a single recursive listing that builds the tree in memory is fine.

Other Information

Prior art:

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CLI version used

aws-cli/2.39.3

Environment details (OS name and version, etc.)

Python/3.15.2 Darwin/27.2.0 source/arm64

Activity

  1. added
    feature-requestA feature should be added or improved.
    needs-triageThis issue or PR still needs to be triaged.
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestA feature should be added or improved.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions