Why does `aws s3 ls s3://mybucket/ --recursive | wc -l` list fewer files than the number of objects mentioned in the AWS web UI in my S3 bucket?

I have an AWS S3 bucket s3://mybucket/. Running the following command to count all files:

aws s3 ls s3://mybucket/ --recursive | wc -l

outputs: 279847

Meanwhile, the AWS console web UI clearly indicates 355,524 objects:

Why does aws s3 ls s3://mybucket/ --recursive | wc -l list fewer files than the number of objects mentioned in the AWS web UI in my S3 bucket?

My quick guess would be versions of an object are counted as part of the entire bucket. Your ls is just getting the latest versions.

99% it’s object versions. Try this:

aws s3api list-object-versions --bucket | grep Key | wc -l

or to get all objects which are NOT the latest:

aws s3api list-object-versions --bucket | grep -v ‘“IsLatest”: true’ | wc -l