How to display only files from aws s3 ls command?

后端 未结 9 790
北恋
北恋 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:56

    You can't do this with just the aws command, but you can easily pipe it to another command to strip out the portion you don't want. You also need to remove the --human-readable flag to get output easier to work with, and the --summarize flag to remove the summary data at the end.

    Try this:

    aws s3 ls s3://mybucket --recursive | awk '{print $4}'
    

    Edit: to take spaces in filenames into account:

    aws s3 ls s3://mybucket --recursive | awk '{$1=$2=$3=""; print $0}' | sed 's/^[ \t]*//'
    

提交回复
热议问题