S3 bucket File with 0 Size #7283
-
Hi Is there any way to find files with 0 size in s3 bucket and daily interval other than list all files in a bucket and iterating over each file to find size Since i have more than 10000 files, it is hard to list all files and it costly operation |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @ssk199441 there may not be a command specifically for that use case but you can find some suggestions here: https://stackoverflow.com/questions/10832777/how-to-find-zero-byte-files-in-amazon-s3 For example using the CLI: Or using an SDK: const getBucketFileSize = async function () {
try {
const response = await s3
.listObjectsV2({
Bucket: //Bucket-name,
Prefix: //Provide Bucket Prefix if available,
})
.promise();
response.Contents.map(item=>{
if(item.Size===0){
console.log(item)
}
})
} catch (e) {
console.log("err", e);
}
}; |
Beta Was this translation helpful? Give feedback.
Hi @ssk199441 there may not be a command specifically for that use case but you can find some suggestions here: https://stackoverflow.com/questions/10832777/how-to-find-zero-byte-files-in-amazon-s3
For example using the CLI:
aws s3api list-objects --bucket $BUCKET --prefix $PREFIX --output json --query 'Contents[?Size==`0`]
Or using an SDK: