7

What does "1K-blocks" column mean in the output of df?

$ df
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda7       21181308  19302672    802668  97% /
udev             4070176         4   4070172   1% /dev
tmpfs             815536       972    814564   1% /run

I guess it is the size of a partition in KB?

Does "1K-blocks" mean the size of each block of a partition is 1KB?

Does a "block" here mean the same as a cluster of a file system?

Tim
  • 101,790

2 Answers2

9

The 1K-blocks header is the total space available, measured in 1kB units. Historically, and according to the POSIX standard, df should report the space in units of 512-byte blocks; you can get that output by doing:

POSIXLY_CORRECT=1 df

The "block" here is simply the unit used for the amounts, it is not related to the file system blocksize (or cluster size, if appropriate for the file system involved). For ext2/ext3/ext4 filesystems you can display the file system info with:

sudo dumpe2fs -h /dev/sda7

(replace /dev/sda7 with the file system device).

Note that if you add The Used and Available columns you don't get the total size shown; this is because of blocks that are reserved for root as shown in the output of dumpe2fs as Reserved block count:. Those blocks can only be used by root, the idea behind this is that if a user fills up the filesystem, critical stuff still works and root can fix the problem.

wurtel
  • 16,115
  • When you say 1kB don't you really mean 1KB? 1kB means 1000 bytes and 1KB means 1024 bytes. – kasperd Jan 15 '15 at 22:07
  • 1
    Actually, it's 1kB == 1000 bytes and 1KiB == 1024 bytes, see wikipedia. I'm old school and use k == 1024 in computing which is not correct anymore, so your point is sort of valid. – wurtel Jan 16 '15 at 07:34
3

The second column is the total capacity of each filesystem.

Older versions of Unix used 512-byte blocks in the filesystem, and that's the (undocumented) unit that df used - it showed the number of free blocks (V7 df man page).

When Berkeley changed the block size in the filesystem to 1024 bytes, df (4BSD df source code) still showed the sizes in terms of blocks, and the 4BSD df man page added:

The reported numbers are in file system block units; currently each filesystem block is 1024 bytes long.

In subsequent releases such as 4.2BSD that used variable block sizes, df (4.2BSD df man page) was changed so that:

The reported numbers are in kilobytes.

and most current versions of df do things that way. POSIX specified that df use 512-byte blocks, but included a -k option, to use kilobytes.

Mark Plotnick
  • 25,413
  • 3
  • 64
  • 82