How to display just the name of files using aws s3 ls command

0 votes

I am using the aws cli to list the files in an s3 bucket using the following command

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

This command gives me date , time , size and the file name. But i just want the file names to be displayed.

Is there a way to achieve that?

Sep 5, 2018 in AWS by datageek
• 2,540 points
22,209 views

2 answers to this question.

0 votes

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]*//' 


down voteaccept

You can even check out the details of AWS CLI with the AWS Certification.

answered Sep 5, 2018 by Archana
• 4,170 points
What does " {$1=$2=$3=""; print $0} " command is doing, to print the file name and file size use the following command:

aws s3 ls s3://bucket_name --recursive | awk '{$1=$2="";print $4","$3}' | sed 's/^[ \t]*//'
+1 vote
aws s3 ls s3://<your_bucket_name>/ | awk '{print $4}'

the 4th parameter is the filename
answered Mar 17, 2019 by anonymous
Don't I need to use --recursive?

Related Questions In AWS

0 votes
0 answers
+3 votes
6 answers

How to move files from amazon ec2 to s3 bucket using command line

Hey, 3 ways you can do this: To ...READ MORE

answered Oct 9, 2018 in AWS by Omkar
• 69,220 points
20,001 views
0 votes
1 answer

How to download the latest file in a S3 bucket using AWS CLI?

You can use the below command $ aws ...READ MORE

answered Sep 6, 2018 in AWS by Archana
• 4,170 points
19,855 views
–1 vote
1 answer

How to decrypt the encrypted S3 file using aws-encryption-cli --decrypt

Use command : aws s3 presign s3://mybucket/abc_count.png you get ...READ MORE

answered Oct 22, 2018 in AWS by Priyaj
• 58,020 points
5,204 views
0 votes
1 answer

How to measure the total size of an S3 bucket using python?

Hi@akhtar, You can do this tasks using Boto. ...READ MORE

answered Apr 15, 2020 in AWS by MD
• 95,460 points
5,641 views
0 votes
1 answer

How to edit files in the AWS S3 bucket from CLI?

Hi@akhtar, According to my knowledge,  you can't edit ...READ MORE

answered Jun 8, 2020 in AWS by MD
• 95,460 points
9,685 views
0 votes
1 answer

how to get the list of aws services i am used in aws my account by using the lambda function

Hi@shalk, You can create a session in your ...READ MORE

answered Sep 24, 2020 in AWS by MD
• 95,460 points
2,456 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP