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,490 points
9,072 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
answered Sep 5, 2018 by Archana
• 4,150 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

+3 votes
5 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,030 points
12,374 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,150 points
9,769 views
0 votes
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
• 57,660 points
2,063 views
0 votes
1 answer
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 in AWS by MD
• 57,960 points
358 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 in AWS by MD
• 57,960 points
24 views