Mac Terminal df command is a tool I use to get disk space. For example, before I get a new software or update, I also take a note of my HD space before and after the installation.
I remember I used this command with -b, -k, -m or -g options to get size in 512-bytes-block, kilobytes, megabytes or gigabytes. According to man (manual description) of df, those options may change BLOCKSIZE as well so that if I use "df -h" or "df -H" afterwards, the result will be a size in either binary base or decimal base. I remember that tried this before and it worked fine.
Recently, I try to use "df -b" to reset BLOCKSIZE. I then try "df -h" or "df -H" again, I get size values all as gigabytes (binary or decimal), not expected in 512-bytes. Then I try to use "df -hb" or "df -Hb", the result values are the same(512-bytes-block).
Here are some examples I had before:
$ df -k # this command I get the expected result: 1024-block
Filesystem 512-blocks Used Available ...
/dev/disk1s2 97101344 403566296 572023048 ...
....
$ df -h # the result in binary base, value in 1024-block
Filesystem 1024-blocks Used Avail ...
/dev/disk1s2 97101344 403566296 572023048 ...
....
$ df -H # the result in decimal base, value in 1,000 base
Filesystem Size Used Avail ...
/dev/disk1s2 99431776 413251887 585751601 ...
....
As the above example, "df -k" resets the BLOSKSIZE to kilobytes. However now I repeat thes same commands, but I cannot get the same results:
$ df -k # this command I get the expected result: 1024-block
Filesystem 512-blocks Used Avail ...
/dev/disk1s2 97101344 403566296 572023048 ...
...
$ df -h # the result in binary base but values in Gigabytes
Filesystem Size Used Avail ...
/dev/disk1s2 465Gi 192Gi 273Gi ...
....
$ df -H # the result in decimal base by values in Gigabytes
Filesystem Size Used Avail ...
/dev/disk1s2 500G 207G 293G ...
....
I am not sure what prevent the BLOCKSIZE value not being reset. As a result, I cannot get the size in decimal base (1000 for Kilobytes in decimal base, 1,000,000 for Megabytes in decimal base, …).
By the way, I get the information about usage of df and BLOCKSIZE from:
$ man df
Best Answer
I think your memory of how the command used to work is wrong;
df
has never changedBLOCKSIZE
, only overridden it temporarily. In fact, it cannot changeBLOCKSIZE
for anything but itself -- if you rundf
3 times, each instance gets its own copy of your shell's environment, and can modify its own copy, but can't do anything to the shell's environment (or the other instances' either).That said, I think the only way to get the behavior you want is to actually change
BLOCKSIZE
in the shell's environment:Note that this way of doing things gives the persistent behavior you describe; after setting
BLOCKSIZE
for the parent shell, it's passed to all commands you run in that shell from that point on (until/unless you change it again). If you only want to change it for a particular command, use this instead: