Back

Explore Courses Blog Tutorials Interview Questions
+16 votes
2 views
in AWS by (900 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

+16 votes
by (10.5k 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}'

+10 votes
by (108k 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]*//' 

Learn more about AWS by going through AWS course and master this trending technology.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer
asked Apr 9, 2020 in AWS by Amenda (1.4k points)

Browse Categories

...