Reading Linux Size Output in KiB and Reporting It in KB
Almost every size a Linux shell prints is a kibibyte figure, even when the column header says "K" or "kB". du -k, df -k, ls -l --block-size=K and every counter in /proc count blocks of 1024 bytes. The moment that number leaves the terminal — into a capacity report, a vendor ticket, a spreadsheet somebody outside the team will read — it usually has to be restated in decimal kilobytes of 1000 bytes. That restatement is what this page does.
KB = KiB × 1.024. A du -sk /etc that prints 1480 is 1480 × 1.024 = 1 515.52 KB.The -k Flag Is Not Decimal
-k means "report in units of 1024 bytes". The letter is inherited from an era when nobody distinguished the two scales, and the output has never been changed to match SI.One File, Two Legitimate Numbers
ls shows the first, du the second, and neither of them is wrong./proc Speaks Only in KiB
MemTotal, SwapTotal and the fields in /proc/swaps as bare kB-labelled integers that are in fact kibibytes — eight-digit numbers where a 2.4% gap runs to thousands of kilobytes.Where the 2.4% Actually Bites
df -k figure for a large volume it is several decimal gigabytes, which is enough to make two capacity reports contradict each other.Turning a Terminal Figure Into Kilobytes
Paste the Number the Shell Printed
Drop the integer from du -k, df -k or /proc/meminfo straight into the KiB field. Stray spaces are ignored, and a comma is accepted as a decimal point if your locale produced one.
Read the Decimal Kilobyte Value
The KB field updates as you type, with thousands separated by a space so an eight-digit /proc figure stays legible. Fractional results are shown to eight decimals.
Copy the Bare Number Into the Report
The copy button beside each field puts the plain digits on your clipboard — no unit suffix, no grouping — which is what a ticket field, a CSV column or a shell variable expects.
Reverse It When You Are Checking a Claim
Going the other way is one click: the swap button turns the page into a KB → KiB converter, so a decimal figure from a datasheet or a monitoring dashboard can be restated in the units the shell will actually show you.
Both unit menus are searchable and list every data-storage unit, so the same /proc value can be pushed on to MiB, GiB or plain bytes without leaving the page.
What Each Linux Command Actually Reports
The table below takes figures of the kind these commands print on an ordinary server and restates each one in decimal kilobytes. The first two rows describe the same class of small file measured two different ways — allocation versus content — which is the single most common source of "the two commands disagree" tickets.
| Command | What the number means | KiB | KB |
|---|---|---|---|
du -k script.sh | Blocks allocated to a tiny script | 4 | 4.096 |
ls -l --block-size=K app.log | Apparent size of a small log | 12 | 12.288 |
du -sk /etc | Recursive total of a config tree | 1 480 | 1 515.52 |
df -k /boot | Free space on a small partition | 262 144 | 268 435.456 |
cat /proc/swaps | Configured swap size | 2 097 152 | 2 147 483.648 |
grep MemTotal /proc/meminfo | Installed memory seen by the kernel | 16 316 048 | 16 707 633.152 |
Built for Shell Output
Paste Straight From the Prompt
Numbers arrive from a terminal with whatever spacing the column formatting gave them; the input strips spaces and accepts either decimal separator rather than refusing the value.
Eight-Digit /proc Values Stay Readable
Output is grouped with a space every three digits, and values at or beyond ten billion switch to scientific notation instead of running off the end of the field.
Clipboard Output a Script Can Eat
Copying yields the raw number with no unit and no grouping, so it can be pasted into a monitoring threshold or a spreadsheet cell without any cleanup first.
Any Storage Unit on Either Side
Both dropdowns are searchable and cover bits, decimal units, IEC binary units and transfer-rate units, so one df figure can be expressed in whatever the audience uses.
Questions From the Terminal
Why does du report a different number than ls -l for the same file?
They answer different questions. ls -l reports the apparent size — how many bytes the file contains. du reports how much space the filesystem actually gave it, counted in whole allocation units. A 900-byte script contains 900 bytes but occupies a full unit on disk, so du -k says 4 KiB while ls says 900. Convert whichever one your report is about, and state which one it is.
What does the -k in du -k and df -k actually count?
Units of 1024 bytes — kibibytes — despite the letter K suggesting a thousand. That is why a partition df -k calls 262 144 is 268 435.456 KB in decimal terms. If you are quoting the figure to someone outside the shell, multiply by 1.024 and label it KB, or leave it labelled KiB and let them convert.
Why does du --block-size=KB disagree with du --block-size=K?
Because coreutils treats the two suffixes as genuinely different scales. A bare K (like M and G) means the 1024-based unit, while the two-letter KB form means the 1000-based one. Ask for --block-size=KB and du does the ×1.024 arithmetic for you — but it also rounds up to whole units, so wherever the fraction matters, take the KiB figure and convert it here instead.
Which option makes du print the logical size instead of the space on disk?
--apparent-size. Combined with -k it gives you the content length rounded up to kibibytes rather than the allocated blocks, which is the number that matches what ls -l shows. It is the right choice when you are estimating how much data a transfer will move; the default block accounting is the right choice when you are asking how full the volume is.
A preallocated database file looks huge in ls but tiny in du — which number should I convert?
That is a sparse file: regions that were never written are recorded as holes rather than stored, so the apparent size is large while the consumed blocks are few. Convert the du figure when you are reporting capacity consumed, and the ls figure when you are sizing a copy or a backup — a naive copy expands the holes into real bytes and lands much closer to the apparent size.
No comments yet. Be the first to comment!