13

So I can see S3 console and can get into my folder with files listing but I don't find way to find total number of files in it other than going thru pagination which does not work considering thousands of files.

Volatil3
  • 255
  • 1
  • 2
  • 10
  • 3
    Does this answer your question? [How can I get the size of an Amazon S3 bucket?](https://serverfault.com/questions/84815/how-can-i-get-the-size-of-an-amazon-s3-bucket) – Synexis Jan 24 '21 at 23:51

4 Answers4

20

This will list your objects, and in the end you'll see Total objects count, and size:

aws s3 ls s3://bucketName/path/ --recursive --summarize

just change bucketName with your bucket name and path is actually a folder within a bucket, if you need that as well (or remove it if you want the whole bucket)

you can also use s3api from cli:

aws s3api list-objects --bucket bucketName --query "[length(Contents[])]"

As noted in comment, can take a while in case of a large bucket.

Caldazar
  • 301
  • 2
  • 5
6

This is easy to do in the new S3 console directly.

As shown here, select the S3 bucket, and then select the folder of interest. Next, click the Actions button and select Get total size as shown here:

get total size of selected folder

Then you should get a popup showing you the number of objects in the folder and the calculated size like so:

size results

nonbeing
  • 198
  • 1
  • 6
6

if you just need the number of files without actually printing the files you can pipe what @Caldazer proposed to wc -l like

aws s3 ls s3://bucketName/path/ | wc -l
Jimmar
  • 161
  • 1
  • 3
1

Another way to grab just the number of objects in your bucket is to grep for "Total Objects", which is part of the output automatically displayed when using --summarize:

aws s3 ls s3://bucketName/path/ --recursive --summarize | grep "Total Objects:"

For a folder with 1633 files, this will return:

Total Objects: 1633