[AWS CLI] Download an S3 prefix with its directory name

Created on November 30, 2026

When you copy a prefix recursively with aws s3 cp, paths under the source prefix are reproduced in the destination. To keep the dummy_directory path in this example, copy from its parent prefix and filter the objects.

aws s3 cp s3://example-bucket/some_directory/ ./ \
  --exclude '*' --include 'dummy_directory/*' --recursive

The later --include rule selects the contents of dummy_directory. The command downloads them under ./dummy_directory/.

AWS CLI S3