Recursive list s3 bucket contents with AWS CLI

Viewed 33576
5 Answers

With recent AWS CLI versions, --recursive option is supported.

You can list recursively all the files under a bucket named MyBucket using following command:

aws s3 ls s3://MyBucket/ --recursive

You can list recursively all the files under a folder named MyFolder in the bucket, using following command:

aws s3 ls s3://MyBucket/MyFolder/ --recursive

As @Francisco Cardoso said, the final / is very important. It allows to list the content of the folder instead of the folder itself

For more information, see: https://docs.aws.amazon.com/cli/latest/reference/s3/ls.html

Below one line bash script is able to perform:- how to list all S3 buckets with their objects recursively, list bucket name and count objects also.

/usr/bin/sudo /usr/local/bin/aws s3 ls |awk '{print $NF}'| while read l;do echo -e "#######---$l objects---##########\n\n";/usr/bin/sudo /usr/local/bin/aws s3 ls $l|nl;done
Related