简体   繁体   English

在 S3 中打印与某些特定模式匹配的文件

[英]Print files in S3 matching some specific pattern

I have a S3 bucket, in the bucket i have one folder and inside the folder i have many sub folders like mentioned below.我有一个 S3 存储桶,存储桶中有一个文件夹,文件夹内有许多子文件夹,如下所述。

Bucket path: s3://path1/path2桶路径:s3://path1/path2

Inside path2 folders will be like里面的 path2 文件夹会像

D1D04021200040609001
D1D04021200040612001
D3D04020000040603001
D3D04020000040606001
D6D05091200051512001
D6D05091200051518001
G1S05101200051217001
G1S05101200051218001
G4S05091200051012001
G4S05091200051013001

I have many folders like this.我有很多这样的文件夹。 I just want to check specific file exists or not using a pattern.我只想检查特定文件是否存在或不使用模式。 How can i do this in linux我怎么能在 linux 中做到这一点

aws s3api list-objects --bucket path1/path2 --query "Contents[?contains(Key, `D1D0`)]"

am getting error like.... invalid bucket name bucket name should be in regex我收到类似这样的错误......无效的存储桶名称存储桶名称应该在正则表达式中

I ran the below query我运行了以下查询

 aws s3api list-objects --bucket bucket name --prefix daily/ --query "Contents[?contains(Key, 'A1D0518')]" --query "sum(Contents[].Size)" --output text

But i wonder yi am getting 10 lines of output... i need the total size of the files staring with A1D0518 enter image description here但我想知道 yi 得到 10 行 output...我需要以A1D0518 开头的文件的总大小enter image description here

Kindly help!请帮忙!

It appears that your requirement is to calculate the total size of all objects that contain a given string .看来您的要求是计算包含给定字符串的所有对象的总大小。

This can be done with:这可以通过以下方式完成:

 aws s3api list-objects --bucket my-bucket --query "sum(Contents[?contains(Key, 'E4Y0')].Size)"

If, instead, you are looking for the total size of all objects that start with a given string , use:相反,如果您要查找以给定字符串开头的所有对象的总大小,请使用:

 aws s3api list-objects --bucket my-bucket --prefix E4Y0 --query "sum(Contents[].Size)"

Please note that Prefix looks at the full path, so it might include subdirectories.请注意Prefix查看完整路径,因此它可能包含子目录。 So, first have it print the names with --query Contents[].Key to make sure you are including the correct objects.因此,首先让它使用--query Contents[].Key打印名称,以确保包含正确的对象。

Update based on your comment:根据您的评论更新:

To find objects in a given directory that being with E4Y0 use:要在给定目录中查找带有E4Y0的对象,请使用:

aws s3api list-objects --bucket my-bucket --prefix path1/path2/path3/E4Y0 --query "sum(Contents[].Size)"

But test it first by using this to list the objects being selected:但首先使用它来测试它以列出被选择的对象:

aws s3api list-objects --bucket my-bucket --prefix path1/path2/path3/E4Y0 --query "Contents[].Key"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM