【问题标题】:Recursive list s3 bucket contents with AWS CLI使用 AWS CLI 递归列出 s3 存储桶内容
【发布时间】:2023-03-17 10:34:01
【问题描述】:

如何使用 AWS CLI 递归列出存储桶的所有内容,类似于在 Unix 上使用 find .

aws s3 ls s3://MyBucket --recursive 抱怨未知选项。

http://docs.aws.amazon.com/cli/latest/reference/s3/index.html#directory-and-s3-prefix-operations 声称--recursive 是一个有效参数。

【问题讨论】:

    标签: amazon-web-services amazon-s3 aws-cli


    【解决方案1】:

    aws s3 ls s3://MyBucket --recursive 适合我。

    尝试更新您的 AWS CLI。我的版本是 aws-cli/1.6.2

    aws --version

    【讨论】:

    • 最初的问题是不久前的 1.3.X 版本
    【解决方案2】:

    对于最近的 AWS CLI 版本,支持--recursive 选项。

    您可以使用以下命令递归列出名为 MyBucket 的存储桶下的所有文件:

    aws s3 ls s3://MyBucket/ --recursive
    

    您可以使用以下命令递归列出存储桶中名为MyFolder的文件夹下的所有文件:

    aws s3 ls s3://MyBucket/MyFolder/ --recursive
    

    欲了解更多信息,请参阅:https://docs.aws.amazon.com/cli/latest/reference/s3/ls.html

    【讨论】:

      【解决方案3】:

      我无法正确解释您引用的链接:http://docs.aws.amazon.com/cli/latest/reference/s3/index.html#directory-and-s3-prefix-operations

      但是,我能够使 --recursive 选项与此链接相关:http://docs.aws.amazon.com/cli/latest/reference/s3/index.html#single-local-file-and-s3-object-operations

      根据此链接,cpmvrm 支持 --recursive 选项。

      您正在尝试的是ls

      我尝试将cprm--recursive 选项一起使用,它工作正常。

      【讨论】:

        【解决方案4】:

        您不能通过 - 递归列出存储桶的所有内容 -

        aws s3 ls s3://MyBucket
        

        要列出文件夹中的对象,您需要执行命令为 -

        aws s3 ls s3://MyBucket/MyFolder/
        

        上述命令列出了位于名为 MyFolder 的文件夹中的对象。

        要从 Amazon S3 的此类逻辑层次结构中获取对象列表,您需要在 GET operation 中指定对象的完整键名。

        --递归Command对指定目录或前缀下的所有文件或对象执行。

        谢谢

        【讨论】:

        • 这不再是真的。
        • 最好删除过时的信息
        • 有没有办法只获取文件名而不获取时间戳等?
        【解决方案5】:

        以下一行 bash 脚本能够执行:- 如何递归列出所有 S3 存储桶及其对象,列出存储桶名称和计数对象。

        /usr/bin/sudo /usr/local/bin/aws s3 ls |awk '{print $NF}'| while read l;do echo -e "#######---$l objects---##########\n\n";/usr/bin/sudo /usr/local/bin/aws s3 ls $l|nl;done
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-01-24
          • 2020-11-05
          • 2016-08-26
          • 2017-05-06
          • 1970-01-01
          • 1970-01-01
          • 2010-11-21
          • 1970-01-01
          相关资源
          最近更新 更多