AWS CLI ls return

0

Greetings,

I am using AWS cli in s3 to return the dates of files in buckets, the aim is to find old files to archive/delete.

The syntax that I am using is standard cli syntax. The files have been updated, but it returns the wrong date 2022-11-17?? Not 2023-02-01

aws s3 ls s3:bucket/Europe/ --recursive --human-readable --summarize --query "Contents[?contains(LastModified, '2022-11')].{Key: Key}" --output text | xargs -n1 -t -I 'KEY'

已提問 1 年前檢視次數 370 次
2 個答案
0

Hello,

Please try with the s3api as below to meet your requirements to list the keys based on last modified date

aws s3api list-objects-v2 --bucket bucket_name  --query "Contents[?contains(LastModified, '2023-02-22')].{Key: Key}" --output=text
AWS
已回答 1 年前
profile pictureAWS
專家
kentrad
已審閱 1 年前
0

Hi,

You can use the s3api list-objects command to achieve that:

aws s3api list-objects --bucket MY-BUCKET --query "Contents[?contains(LastModified, '2023-01')].{Key: Key}" --output text

Above allows you to filter the Lastmodified attribute.

Otherwise you can simply run:

aws s3 ls s3://MY-BUCKET --recursive --human-readable --summarize > s3_files.txt    

and see results in the file

profile picture
專家
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南