+18 votes
1 view
in AWS by (910 points)

A tried using the AWS CLI for listing the files in the S3 bucket using:

aws s3 ls s3://myS3bucket --recursive --human-readable --summarize

I just want to view the file names and not the date, time etc.
How can I do that?

2 Answers

+18 votes
by (10.6k points)

  • Is command is used to list S3 objects and common prefixes under a prefix or all S3 buckets.
     
  • Note that the --output and --no-paginate arguments are ignored for this
    command.


    Syntax: aws s3 ls
  • AWS command alone is not sufficient, omit --human reader-readable flag to get the output easier to work with, and the --summarize flag to remove the summary data at the end.
     
  • Try the given code:

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

+11 votes
by (57.5k points)

You can't perform 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.

follow the syntax given below:

aws s3 ls s3://<your_bucket_name> --recursive | awk '{print $4}'

And to add spaces in filenames into account, refer to the following syntax:

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...