0

I am using the aws cli to summarize the number of files and the total size of 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, I'm only after the Total Objects and Total Size output, e.g.:

Total Objects: 10
   Total Size: 2.9 MiB

How can I only display the Total Objects and Total Size while suppressing/hiding the rest?

Borealis
  • 155
  • 1
  • 8

1 Answers1

1

Either use tail to show the last few lines or grep to filter the output based on the "Total" keyword at the beginning of the line (optionally with the extra whitespace), like:

aws s3 ls s3://mybucket --recursive --human-readable --summarize|tail -n2

Or

aws s3 ls s3://mybucket --recursive --human-readable --summarize|grep -e '^\s*Total'
Oldskool
  • 2,025
  • 1
  • 16
  • 27