Format aws cli command out

by | Apr 21, 2025 | IT Tips | 0 comments

A typical listing from aws s3 ls --human-readable --recursive s3://myBucket/Pictures will look like the following

2018-04-11 01:12:31 956.9 KiB Pictures/Personal Photos/images jan 09/feb 08/IMG_20080227_0114.JPG
2018-04-11 01:12:32 743.7 KiB Pictures/Personal Photos/images jan 09/feb 08/IMG_20080227_0115.JPG
2018-04-11 01:12:32 1022.0 KiB Pictures/Personal Photos/images jan 09/feb 08/IMG_20080227_0116.JPG
2018-04-11 01:12:33 858.5 KiB Pictures/Personal Photos/images jan 09/feb 08/IMG_20080227_0117.JPG

But how to get a simple file listing?

aws s3api list-objects --bucket myBucket --prefix Pictures --query 'Contents[].[Key]' --output text

Will give you a nicer out put

Pictures/Personal Photos/images jan 09/feb 08/IMG_20080227_0114.JPG
Pictures/Personal Photos/images jan 09/feb 08/IMG_20080227_0115.JPG
Pictures/Personal Photos/images jan 09/feb 08/IMG_20080227_0116.JPG
Pictures/Personal Photos/images jan 09/feb 08/IMG_20080227_0117.JPG

You can then script the output

Also if you want to clean up an upload perhaps one with thousands of .DS_Store files in it you can

Dry run first

aws s3 rm s3://myBucket/Pictures --dryrun --recursive --exclude "*" --include "*.DS_Store"

Then for real

aws s3 rm s3://myBucket/Pictures --recursive --exclude "*" --include "*.DS_Store

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.