删除aws s3上的文件
作者:互联网
简单的删除
aws s3 rm s3://com.****.prd/:tmp/file_name.json # 删除文件
aws s3 rm s3://com.****.prd/:tmp/ --recursive # 删除文件夹
删除某个时间点前的文件
vim s3_file_delete.sh
s3bucket="s3://BucketName" s3dirpath="s3://BucketName/WithOrWithoutDirectoryPath/" aws s3 ls $s3dirpath --recursive | while read -r line; do createDate=`echo $line|awk {'print $1" "$2'}` createDate=`date -d"$createDate" +%s` olderThan=`date --date "159 days ago" +%s` if [[ $createDate -lt $olderThan ]] then fileName=`echo $line|awk '{a="";for (i=4;i<=NF;i++){a=a" "$i}print a}' |awk '{ sub(/^[ \t]+/, ""); print }'` if [[ $fileName != "" ]] then #echo "$s3bucket/$fileName" aws s3 rm "$s3bucket/$fileName" fi fi done;
参考文献:
https://www.thinbug.com/q/50467698
标签:删除,s3,createDate,aws,date,line 来源: https://www.cnblogs.com/smartcoding/p/14250642.html