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,460 points

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,060 points
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
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,530 points
0 votes
1 answer
+1 vote
3 answers

How to get ARN for s3 Bucket using aws cli .

An ARN is a non-opaque, constructible identifier, ...READ MORE

answered Aug 16, 2018 in AWS by Priyaj
• 57,530 points
0 votes
1 answer
0 votes
1 answer

How to add SSL certificate to AWS EC2 with the help of new AWS Certificate Manager service

refer this link You can't install the certificates ...READ MORE

answered Jul 19, 2018 in AWS by Priyaj
• 57,530 points