File size in human readable format

GNU Coreutils contains an apparently rather unknown little tool called numfmt for numeric conversion, that does what you need:

$ numfmt --to=iec-i --suffix=B --format="%.3f" 4953205820
4.614GiB

I think that suits your needs well, and isn’t as large or hackish as the other answers.

If you want a more powerful solution, look at my other answer.


Is there any reason you are not using

ls -lh

command ? If you are on a Linux system which has been released in the last few years, you have this functionality.

Tags:

Linux

Bash