AWS CLI S3存储桶删除具有日期条件的对象 [英] aws cli s3 bucket remove object with date condition

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

问题描述

我如何递归删除aws cli s3存储桶中具有日期条件的对象

how do i remove aws cli s3 bucket remove object with date condition recursively

我正在使用此命令进行列表

i am using this command for listing

aws s3 ls --recursive s3://uat-files-transfer-storage/ | awk '$1 < "2018-02-01 11:13:29" {print $0}' | sort -n

它运行得很好,但是当我将此命令与rm一起使用时,它会删除所有文件

its run perfectly but when i use this command with rm its delete all files

aws s3 rm --recursive s3://uat-files-transfer-storage/ | awk '$1 < "2018-02-01 11:13:29" {print $0}' | sort -n

任何解决方案

推荐答案

您处在正确的轨道上.要了解发生了什么,让我们逐步查看您的命令正在做什么.

You're on the right track. To understand what's going on, let's look at what your commands are doing step by step.

aws s3 ls --recursive s3://uat-files-transfer-storage/ | awk '$1 < "2018-02-01 11:13:29" {print $0}' | sort -n

此命令以递归方式列出存储桶中的所有文件,检查输出是否符合特定条件,然后对结果输出行进行排序.

This command lists all files in the bucket recursively, checks the output for a specific condition, and then sorts the resultant output lines.

aws s3 rm --recursive s3://uat-files-transfer-storage/ | awk '$1 < "2018-02-01 11:13:29" {print $0}' | sort -n

此命令以递归方式删除存储桶中的所有文件,检查特定条件下的输出,然后对结果输出行进行排序.因此,第二个命令将首先删除您的所有文件!

This command deletes all the files in your bucket recursively, checks the output for a specific condition, and then sorts the resultant output lines. So the second command deletes all your files first!

您要做的是列出存储桶中的所有文件,检查它们是否符合特定条件,然后然后将其删除.这应该起作用:

What you want to do is list all the files in your bucket, check that they meet a certain criteria, and then delete them. This should work:

aws s3 ls --recursive s3://uat-files-transfer-storage/ | awk '$1 < "2018-02-01 11:13:29" {print $4}' | xargs -n1 -t -I 'KEY' aws s3 rm s3://uat-files-transfer-storage/'KEY'

请小心!这不会在删除之前提示您,这是一种错误地清理整个存储桶的简便方法.

BE CAREFUL! This won't prompt you before deleting, and it's an easy way to clean out your whole bucket by mistake.

这篇关于AWS CLI S3存储桶删除具有日期条件的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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