Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ Get the size of the given directory.
Available parameters:

* -r/--recursive: also add sizes of sub-directories recursively.
* -H/--human-readable: print sizes in human readable format (eg, 234M, 2.3G).

## s4cmd Control Options

Expand Down
20 changes: 19 additions & 1 deletion s4cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,22 @@ def del_handler(self, args):
def du_handler(self, args):
'''Handler for size command'''
for src, size in self.s3handler().size(args[1:]):
message('%s\t%s' % (size, src))
if self.opt.humanread:
if size > 2*1099511627776: # 2^40
size_in_units = float(size) / 1099511627776
units = 'Tb'
elif size > 2*1073741824: # 2^30
size_in_units = float(size) / 1073741824
units = 'Gb'
elif size > 2*1048576: # 2^20
size_in_units = float(size) / 1048576
units = 'Mb'
elif size > 2048:
size_in_units = float(size) / 1024
units = 'Kb'
message('%0.2f %s\t%s' % (size_in_units, units, src))
else:
message('%s\t%s' % (size, src))

@log_calls
def _totalsize_handler(self, args):
Expand Down Expand Up @@ -1842,6 +1857,9 @@ def main():
parser.add_option(
'-r', '--recursive', help='recursively checking subdirectories',
dest='recursive', action='store_true', default=False)
parser.add_option(
'-H', '--human-readable', help='print sizes in human readable format (eg, 234M, 2.3G)',
dest='humanread', action='store_true', default=False)
parser.add_option(
'-s', '--sync-check', help='check file md5 before download or upload',
dest='sync_check', action='store_true', default=False)
Expand Down