AWS 在 S3 存储桶中查找最大文件大小 [英] AWS find max file size in S3 bucket
问题描述
我想找到 S3 存储桶中最大文件的大小和名称.
I want to find the size and name of the biggest file in my S3 bucket.
目前我有:
aws s3api list-objects --bucket bucket-name --output json --query "[max(Contents[].Size), length(Contents[])]"
这不允许我看到文件的名称.
which does not allow me to see the name of the file.
我还有一个命令可以列出存储桶上所有文件的详细信息:
I also have the command to list the details of all files on the bucket:
aws s3api list-object-versions --bucket bucket-name --query 'Versions[*].Size'
什么命令会给我 S3 存储桶上最大文件的名称和大小?
What command will give me the name and size of the largest file(s) on the S3 bucket?
推荐答案
仅使用 AWS CLI,这将找到最大的文件:
Using AWS CLI only, this will find the largest file:
aws s3api list-objects-v2 --bucket bucket-name --query "sort_by(Contents, &Size)[-1:]"
或包含非当前版本(如果适用):
or to include non-current versions if applicable:
aws s3api list-object-versions --bucket bucket-name --query "sort_by(Versions[*], &Size)[-1:]"
可选调整:
- 将
-1
替换为-N
以找到最大的 N 个文件. - 在
--query
末尾包含.[Key,Size]
以仅选择这些字段.
- Replace
-1
with-N
to find the largest N files. - Include
.[Key,Size]
at the end of the--query
to select only those fields.
遗憾的是,我认为过滤是在客户端完成的,因为在大存储桶上运行时下载了 28 MB.然而,尽管速度不快,但它仍然是一个有用的 1-liner.
Sadly I think the filtering is done client side because this downloaded 28 MB when run on a large bucket. However it is still a useful 1-liner despite not being quick.
这篇关于AWS 在 S3 存储桶中查找最大文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!