Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I am using the aws cli to list the files in an s3 bucket using the following command (documentation):

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

This command gives me the following output:

2013-09-02 21:37:53   10 Bytes a.txt

2013-09-02 21:37:53  2.9 MiB foo.zip

2013-09-02 21:32:57   23 Bytes foo/bar/.baz/a

2013-09-02 21:32:58   41 Bytes foo/bar/.baz/b

2013-09-02 21:32:57  281 Bytes foo/bar/.baz/c

2013-09-02 21:32:57   73 Bytes foo/bar/.baz/d

2013-09-02 21:32:57  452 Bytes foo/bar/.baz/e

2013-09-02 21:32:57  896 Bytes foo/bar/.baz/hooks/bar

2013-09-02 21:32:57  189 Bytes foo/bar/.baz/hooks/foo

2013-09-02 21:32:57  398 Bytes z.txt

Total Objects: 10

   Total Size: 2.9 MiB

However, this is my desired output:

a.txt

foo.zip

foo/bar/.baz/a

foo/bar/.baz/b

foo/bar/.baz/c

foo/bar/.baz/d

foo/bar/.baz/e

foo/bar/.baz/hooks/bar

foo/bar/.baz/hooks/foo

z.txt

How can I omit the date, time and file size in order to show only the file list?

1 Answer

0 votes
by (44.4k points)

Remove --human-readable and --summarize to get the desired results. 

--recursive means the command will repeat until the end. This makes it read every instance on the folder.

Use this:

aws s3 ls s3://bucketname --recursive | awk '{print $4}'

Use this one to take the spaces between the filenames.

aws s3 ls s3://bucketname --recursive | awk '{$1=$2=$3=""; print $0}' | sed 's/^[ \t]*//'

Related questions

+16 votes
2 answers

Want to get 50% Hike on your Salary?

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

+1 vote
1 answer

Browse Categories

...