· 7 years ago · May 19, 2018, 03:44 AM
1aws s3api list-objects --bucket BUCKETNAME --output json --query "[sum(Contents[].Size), length(Contents[])]"
2
3aws s3 ls --summarize --human-readable --recursive s3://bucket-name/
4
5aws s3 ls --summarize --human-readable --recursive s3://bucket-name/directory
6
7aws cloudwatch get-metric-statistics --namespace AWS/S3 --start-time 2015-07-15T10:00:00 --end-time 2015-07-31T01:00:00 --period 86400 --statistics Average --region eu-west-1 --metric-name BucketSizeBytes --dimensions Name=BucketName,Value=toukakoukan.com Name=StorageType,Value=StandardStorage
8
9#!/bin/bash
10bucket=$1
11now=$(date +%s)
12aws cloudwatch get-metric-statistics --namespace AWS/S3 --start-time "$(echo "$now - 86400" | bc)" --end-time "$now" --period 86400 --statistics Average --region eu-west-1 --metric-name BucketSizeBytes --dimensions Name=BucketName,Value="$bucket" Name=StorageType,Value=StandardStorage
13
14aws s3 ls s3://bucket/folder --recursive | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}'
15
16pip install s4cmd
17
18s4cmd du -r s3://bucket-name
19
20<?php
21if (!class_exists('S3')) require_once 'S3.php';
22
23// Instantiate the class
24$s3 = new S3('accessKeyId', 'secretAccessKey');
25S3::$useSSL = false;
26
27// List your buckets:
28echo "S3::listBuckets(): ";
29echo '<pre>' . print_r($s3->listBuckets(), 1). '</pre>';
30
31$totalSize = 0;
32$objects = $s3->getBucket('name-of-your-bucket');
33foreach ($objects as $name => $val) {
34 // If you want to get the size of a particular directory, you can do
35 // only that.
36 // if (strpos($name, 'directory/sub-directory') !== false)
37 $totalSize += $val['size'];
38}
39
40echo ($totalSize / 1024 / 1024 / 1024) . ' GB';
41?>
42
43s3cmd du -H s3://Mybucket
4497G s3://Mybucket/
45
46cat report.csv | awk -F, '{printf "%.2f GB %s %s n", $7/(1024**3 )/24, $4, $2}' | sort -n
47
48void Main() {
49 var s3Client = new AmazonS3Client("accessKey", "secretKey", RegionEndpoint.???);
50 var stop = false;
51 var objectsCount = 0;
52 var objectsSize = 0L;
53 var nextMarker = string.Empty;
54
55 while (!stop) {
56 var response = s3Client.ListObjects(new ListObjectsRequest {
57 BucketName = "",
58 Marker = nextMarker
59 });
60
61 objectsCount += response.S3Objects.Count;
62 objectsSize += response.S3Objects.Sum(
63 o =>
64 o.Size);
65 nextMarker = response.NextMarker;
66 stop = response.S3Objects.Count < 1000;
67 }
68
69 new {
70 Count = objectsCount,
71 Size = objectsSize.BytesToString()
72 }.Dump();
73}
74
75static class Int64Extensions {
76 public static string BytesToString(
77 this long byteCount) {
78 if (byteCount == 0) {
79 return "0B";
80 }
81
82 var suffix = new string[] { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
83 var longBytes = Math.Abs(byteCount);
84 var place = Convert.ToInt32(Math.Floor(Math.Log(longBytes, 1024)));
85 var number = Math.Round(longBytes / Math.Pow(1024, place), 1);
86
87 return string.Format("{0}{1}", Math.Sign(byteCount) * number, suffix[place]);
88 }
89}
90
91aws s3 ls s3://bucketnanme --recursive --human-readable --summarize
92
932016-05-17 00:28:14 0 Bytes folder/
942016-05-17 00:30:57 4.7 KiB folder/file.jpg
952016-05-17 00:31:00 108.9 KiB folder/file.png
962016-05-17 00:31:03 43.2 KiB folder/file.jpg
972016-05-17 00:31:08 158.6 KiB folder/file.jpg
982016-05-17 00:31:12 70.6 KiB folder/file.png
992016-05-17 00:43:50 64.1 KiB folder/folder/folder/folder/file.jpg
100
101Total Objects: 7
102
103 Total Size: 450.1 KiB
104
105s3ls -s -H bucketname
106
107s3-du.sh testbucket.jonzobrist.com
108149 files in bucket testbucket.jonzobrist.com
10911760850920 B
11011485205 KB
11111216 MB
11210 GB
113
114#!/bin/bash
115
116if [ “${1}†]
117then
118NUM=0
119COUNT=0
120for N in `s3ls ${1} | awk ‘{print $11}’ | grep [0-9]`
121do
122NUM=`expr $NUM + $N`
123((COUNT++))
124done
125KB=`expr ${NUM} / 1024`
126MB=`expr ${NUM} / 1048576`
127GB=`expr ${NUM} / 1073741824`
128echo “${COUNT} files in bucket ${1}â€
129echo “${NUM} Bâ€
130echo “${KB} KBâ€
131echo “${MB} MBâ€
132echo “${GB} GBâ€
133else
134echo “Usage : ${0} s3-bucketâ€
135exit 1
136fi
137
138s3list=`aws s3 ls | awk '{print $3}'`
139for s3dir in $s3list
140do
141 echo $s3dir
142 aws s3 ls "s3://$s3dir" --recursive --human-readable --summarize | grep "Total Size"
143done
144
145s3cmd du s3://Mybucket -H
146
147s3cmd du s3://Mybucket --human-readable
148
149// make sure that you are using correct region (where the bucket is) to get new Amazon S3 client
150$client = AwsS3S3Client::factory(array('region' => $region));
151
152// check if bucket exists
153if (!$client->doesBucketExist($bucket, $accept403 = true)) {
154 return false;
155}
156// get bucket objects
157$objects = $client->getBucket(array('Bucket' => $bucket));
158
159$total_size_bytes = 0;
160$contents = $objects['Contents'];
161
162// iterate through all contents to get total size
163foreach ($contents as $key => $value) {
164 $total_bytes += $value['Size'];
165}
166$total_size_gb = $total_size_bytes / 1024 / 1024 / 1024;
167
168aws s3 ls s3://bucket/folder/ --recursive | awk '{sz+=$3} END {print sz/1024/1024 "MB"}'