AWS 在 S3 存储桶中查找最大文件大小 [英] AWS find max file size in S3 bucket

查看:53
本文介绍了AWS 在 S3 存储桶中查找最大文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆