Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ls in awscli returns "PRE". Why and how to get rid of it

Using awscli in git bash, the command

aws s3 ls "s3://directory/"

returns a list of

PRE "filename"

This is inconvenient as I need to do further commands on the output and I only need the file/directory names within the given directory.

For instance, it would be nice to be able to do:

for dir in $(aws s3 ls s3://directory/) do
 aws s3 ls $dir | grep .json;
done

Any suggestions to work around this?

like image 692
Boris Avatar asked Jun 30 '17 11:06

Boris


People also ask

What does pre mean in AWS CLI?

list buckets. List the objects in a specific bucket and folder. It returns all the objects along with their date and time of creation, size and name. Prefixes (folders) are represented by “PRE” and do not return the date or time. $ aws s3 ls.

What is pre in AWS S3?

Pre-signed URLs are used to provide short-term access to a private object in your S3 bucket. They work by appending an AWS Access Key, expiration time, and Sigv4 signature as query parameters to the S3 object. There are two common use cases when you may want to use them: Simple, occasional sharing of private files.

Why my AWS CLI is not working?

If the aws command cannot be found after first installing or updating the AWS CLI, you might need to restart your terminal for it to recognize any PATH updates. If the aws command cannot be found after first installing or updating the AWS CLI, it might not have been fully installed.

What is ls command in aws?

The following ls command will recursively list objects in a bucket. Rather than showing PRE dirname/ in the output, all the content in a bucket will be listed in order: aws s3 ls s3://mybucket --recursive.


1 Answers

you are able to do that with something like

aws s3 ls s3://directory --recursive | awk '{print $4}' | grep .json
like image 130
Frederic Henri Avatar answered Sep 29 '22 11:09

Frederic Henri