【问题标题】:s3cmd: searching for files based on extension and delete from buckets3cmd:根据扩展名搜索文件并从存储桶中删除
【发布时间】:2012-07-24 11:15:44
【问题描述】:

我有一个 S3 存储桶,其中包含数千个文件夹和这些文件夹中的许多 txt 文件。

我想列出存储桶中的所有 txt 文件,以便检查它们是否可移动。然后删除它们,如果它们是。

知道如何使用 s3cmd 执行此操作吗?

【问题讨论】:

    标签: amazon-s3 amazon-web-services s3cmd


    【解决方案1】:

    这相当简单,但取决于您希望检查的复杂程度。假设您想删除文件名中包含 'foo' 的每个文本文件:

    s3cmd --recursive ls s3://mybucket |
        awk '{ print $4 }' | grep "*.txt" | grep "foo" | xargs s3cmd del
    

    如果您想要比 grep 处理的更复杂的检查,只需将前三个命令重定向到文件,然后手动编辑文件或使用 awkperl 或任何您喜欢的工具,然后 @ 987654324@ 输出到s3cmd (取决于检查,您也可以使用管道完成所有操作):

    s3cmd --recursive ls s3://mybucket | awk '{ print $4 }' | grep "*.txt" > /tmp/textfiles
    magic-command-to-check-filenames /tmp/textfiles
    cat /tmp/textfiles | xargs s3cmd del
    

    【讨论】:

      猜你喜欢
      • 2022-01-13
      • 2017-02-01
      • 2014-10-18
      • 2012-06-23
      • 2012-06-29
      • 2018-05-16
      • 2021-12-13
      • 2016-10-23
      • 1970-01-01
      相关资源
      最近更新 更多