0

I'm trying to get total free disk space to make its filling prognosis.

The ways I've already used

df -h

Filesystem      Avail
/dev/md1p1      182G
none            488K
tmpfs           32G
tmpfs           13G
tmpfs           5.0M
tmpfs           6.3G



df -Bk

Filesystem      1K-blocks  Available
/dev/md1p1     431550588K 189781520K
none                 492K       488K
tmpfs           32869168K  32869168K
tmpfs           13147668K  13147504K
tmpfs               5120K      5120K
tmpfs            6573832K   6573832K

What does prefix 'K' mean? Kilobytes?

What does 1K-blocks column mean?

How can I print all data measured in bytes?

2
  • If you read man df (the reference manual pages) it'll tell you exactly what the K means, and whether it's 1000 bytes or 1024 Commented Oct 27, 2023 at 7:17
  • Disk devices work in blocks (whose size is determined by the type of file system). Blocks are always a multiple of 512 bytes, but normally 4096 bytes -- you can determine this by using stat -f on any file in the file system. Your resultant bytes will always be exactly divisible by the block size anyway, so not clear why a number like 98112299008 would be any more helpful. Commented Oct 27, 2023 at 8:08

1 Answer 1

2

With the GNU implementation of df, as found on Ubuntu, you can use:

df --block-size=1

Or:

df -B 1

That explicitly sets the blocks to be 1 byte and displays the result

That takes precedence over the $DF_BLOCK_SIZE variable, itself taking precedence over $BLOCK_SIZE itself taking precedence over $BLOCKSIZE which are ways to specify the block size globally (and except for $DF_BLOCK_SIZE affect other commands such as GNU ls -s or GNU du).

The default block size for utilities in GNU coreutils when the $POSIXLY_CORRECT variable is not set is the Kibibyte aka KiB, aka K¹ which is 1024 or 210 bytes. So df by default is the same as df -BK or df -B1024.

See:

info df 'Block size'

for details.

So to get just two columns: filesystem source and available space (to non-root users) in bytes:

df --block-size=1 --output=source,avail

¹ but not KB/kB which is ambiguous and most of the times means 1000 bytes (kilobyte).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .