Reputation: 5860
There are many programs in Linux which would show the size of a file, some of them show it in blocks, some are in bytes. But when it comes to some human readable form, like ls -sh, lvs, dd bs=size and so many, how do we decide if it's a multiple of 1024 or 1000 when we see a kb, KB, mB, MB, K, G etc. Some distinguish them with capitalization like lvs, some with different characters like dd, however, is there a general rule of these kinds of things cause I can't find it so far. Thanks.
Upvotes: 12
Views: 8136
Reputation: 9140
If you look at man units, you'll see a description of the two types of units. Decimal and Binary. Decimal units like Kilobyte (KB) and Megabyte (MB) are in multiples of 1000 (10^3) while Binary units like Kibibyte (KiB) and Mebibyte (MiB) are in multiples of 1024 (2^10).
If the unit being displayed includes a binary prefix like KiB, MiB, GiB, you can be certain it's 1024. For unclear units, a general thumb rule:
Ubuntu published a policy in 2010 for their units which appears to be reasonably consistent across Linux distributions, although not guaranteed:
Use base-10 for:
Use base-2 for:
For file sizes there are two possibilities:
1 As noted by Kris Avi in a comment, some command-line tools developed before this policy may use only base-2 values but indicate decimal units, and may not have changed in order to avoid breaking existing parsing scripts.
Upvotes: 20