Tar – Can `tar –list -v` List File Size in Human-Readable Format?

size;tar

I want to list members of tar files verbosely, and show the file size in human-readable format not in bytes, does the tar has the option to do this?

Best Answer

There's no built-in tar option, but you can filter its output. For example, using humanize:

#!/usr/bin/env python

import fileinput
import humanize

for line in fileinput.input():
    (perm, owner, size, date, time, filename) = tuple(line.split())
    print '{0} {1} {2:>9} {3} {4} {5}'.format(perm, owner, humanize.naturalsize(size, gnu=True), date, time, filename)

Save this as e.g. humantvf, then

tar tvf ... | ./humantvf