How to display only files from aws s3 ls command?

后端 未结 9 895
北恋
北恋 2021-01-01 08:09

I am using the aws cli to list the files in an s3 bucket using the following command (documentation):

aws s3 ls s3://mybucket --recursive --human-readable --         


        
9条回答
  •  星月不相逢
    2021-01-01 08:53

    I would suggest not depending on the spacing and fetching the 4th field.

    You technically want the last field regardless of which position it was in.

    So it's safer to use rev to your advantage...
    rev reverses the string input char by char
    so when you pipe the aws s3 ls out put to rev you have everything reversed, including the positions of the fields, so the last field always becomes the first field.
    Instead of figuring out where the last field would be, you just rev, get first, then rev again because the characters in the field would be in reverse as well. (e.g. 2013-09-02 21:32:57 23 Bytes foo/bar/.baz/a becomes a/zab./rab/oof setyB 32 75:23:12 20-90-3102)
    then cut -d" " -f1would retrieve the first fielda/zab./rab/oof
    then
    revagain to getfoo/bar/.baz/a`

    aws s3 ls s3://mybucket --recursive | rev | cut -d" " -f1 | rev

提交回复
热议问题