Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

df in bytes

136 views
Skip to first unread message

contr...@gmail.com

unread,
Nov 23, 2016, 6:50:34 AM11/23/16
to

Is there any way to get df output in Bytes, not in 512-blocks bytes ?

macmini2:~ Sanford$ df
Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
/dev/disk1 974389248 51594744 922282504 6% 6513341 115285313 5% /
devfs 357 357 0 100% 618 0 100% /dev
map -hosts 0 0 0 100% 0 0 100% /net
map auto_home 0 0 0 100% 0 0 100% /home

Janis Papanagnou

unread,
Nov 23, 2016, 7:18:48 AM11/23/16
to
Not sure whether it is standard but this works for me...

$ DF_BLOCK_SIZE=1 df


Janis

Dan Espen

unread,
Nov 23, 2016, 12:36:27 PM11/23/16
to
You are probably looking for:

df -h

Filesystem Size Used Avail Use% Mounted on
/dev/sdb3 50G 12G 36G 25% /
/dev/sdb1 477M 148M 300M 33% /boot
/dev/sdb5 66G 52M 63G 1% /junk
/dev/sdc1 917G 210G 661G 25% /home
/dev/sda1 917G 225G 646G 26% /back



--
Dan Espen

Lew Pitcher

unread,
Nov 23, 2016, 12:36:38 PM11/23/16
to
On Wednesday November 23 2016 07:18, in comp.unix.shell, "Janis Papanagnou"
df (GNU coreutils) 6.12 accepts a -B (or --block-size=) argument to do the
same thing.

If the OP has GNU df, then
df -B 1
or
df --block-size=1
should also work

--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

Auric__

unread,
Nov 23, 2016, 10:52:58 PM11/23/16
to
Lew Pitcher wrote:

> On Wednesday November 23 2016 07:18, in comp.unix.shell, "Janis Papanagnou"
> <janis_pa...@hotmail.com> wrote:
>
>> On 23.11.2016 12:50, contr...@gmail.com wrote:
>>>
>>> Is there any way to get df output in Bytes, not in 512-blocks bytes ?
>>>
>>> macmini2:~ Sanford$ df
[snip]
>> Not sure whether it is standard but this works for me...
>>
>> $ DF_BLOCK_SIZE=1 df
>
>
> df (GNU coreutils) 6.12 accepts a -B (or --block-size=) argument to do the
> same thing.
>
> If the OP has GNU df, then
> df -B 1
> or
> df --block-size=1
> should also work

Assuming that the machine is a Mac (based on the name "macmini2"), it's the
BSD version of df and related utils. I just checked, and none of the above
work on *my* Mac. ('df -h' ("human-readable") works as expected.) The man
page doesn't list any way to retrieve single-byte blocks.

--
...if not by storm, at least by mild sprinkle...
-- D. Alexander Garrett

Janis Papanagnou

unread,
Nov 24, 2016, 2:22:13 AM11/24/16
to
Then I see two potential options for the OP; install the GNU tools in
/usr/local (and set the PATH appropriately), or postprocess the output
of df (e.g. reformatting with awk). The latter is easier if that BSD df
has some option switch to produce consistent output, say using df -h
or df -k. It's noteworthy to point out that even if displaying the byte
size [on Lunux] the output will still be a multiple of the blocksize
(i.e. there's no finer resolution), so postprocessing df -k should be
the simplest way.

Janis

Thomas 'PointedEars' Lahn

unread,
Nov 24, 2016, 3:55:09 PM11/24/16
to
Lew Pitcher wrote:

> On Wednesday November 23 2016 07:18, in comp.unix.shell, "Janis
> Papanagnou" <janis_pa...@hotmail.com> wrote:

It’s attribution _line_, not attribution novel.

>> On 23.11.2016 12:50, contr...@gmail.com wrote:
>>>
>>> Is there any way to get df output in Bytes, not in 512-blocks bytes ?

Probably ”512-byte blocks” is meant here.
None of what was mentioned so far can be achieved with POSIX df(1):

<http://pubs.opengroup.org/onlinepubs/9699919799/utilities/df.html>

However, <http://ss64.com/osx/df.html> suggests that df(1) on OS X, as
indicated by the “macmini” in the OP, outputs bytes by default (why would
there be “-b” and “-k” options if it would not?).

But although it might not be pretty, the standards-compliant solution
appears to me to be very simple: Multiply all non-percentage numbers by 512.

(export LC_ALL=C; (df -P || df) | awk '
function blockmul (i) {
res = i;
if (match(i, /^[[:digit:]]+$/)) { res *= 512 };
return res;
}

{
printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s %s\n", $1, blockmul($2),
blockmul($3), blockmul($4), $5, blockmul($6), blockmul($7), $8,
$9, $10;
}
')

There is probably a more elegant way, but this WFM.

--
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

Christian Weisgerber

unread,
Nov 25, 2016, 8:30:10 AM11/25/16
to
On 2016-11-24, Thomas 'PointedEars' Lahn <Point...@web.de> wrote:

> However, <http://ss64.com/osx/df.html> suggests that df(1) on OS X, as
> indicated by the “macmini” in the OP, outputs bytes by default (why would
> there be “-b” and “-k” options if it would not?).

More likely it's just a BSD df(1), whose default output block size
can be set with the BLOCKSIZE environment variable, and -b can be
used to override this.

Also, setting BLOCKSIZE to 1 is ignored and produces the warning
"df: minimum blocksize is 512".

--
Christian "naddy" Weisgerber na...@mips.inka.de

Thomas 'PointedEars' Lahn

unread,
Nov 25, 2016, 10:06:56 AM11/25/16
to
Thanks, makes sense.
0 new messages