Skip to content

Navigation Menu

Sign in
Sign up

du reports size in kilobytes, not bytes #1546

rwp0 started this conversation in General
Discussion options

There's no mention of kilobytes in the command documentation below:

I was trying to convert the result wih Number::Bytes::Human, and my assumption was the result will be in bytes. It seems to follow du, but explicit mention of the unit size would help many Perl users.


du($path)

Returns the disk usage of $path.

task "du", "server01", sub {
 say "size of /var/www: " . du("/var/www");
};

This command will not be reported.

https://metacpan.org/pod/Rex::Commands::Fs#du($path)

You must be logged in to vote

Replies: 1 comment

Comment options

There's no mention of kilobytes in the command documentation below:

I believe Rex docs doesn't mention the measurement unit of the value because Rex itself doesn't do any conversions itself or make any guarantees/assumptions about the unit.

[...] my assumption was the result will be in bytes.

I'd like to better understand what made you assume the value would be in bytes. Does the du command return the size in bytes on the systems you manage?

It seems to follow du

Yes, Rex::Commands::Fs::du() does exactly that: calls the du command on the managed system (more precisely, it calls du -s).

but explicit mention of the unit size would help many Perl users.

I'm afraid that guaranteeing uniform reporting units could quickly get out of hand, because du on Linux, *BSD, Solaris, Mac OS X, etc. have different command line flags, and/or configured via different environment variables. Not sure if there's a different pre-existing solution for getting disk usage in a uniform way (or whether we would still want to to call that du) 🤔

Currently I don't think it would be responsible to promise that Rex core will become that uniform frontend to masks all those differences (though I'm open to discuss ideas about how it would be possible in a sustainable way).

What might make more sense for Rex core is to clarify that Rex::Commands::Fs::du() is a pass-through for du on the managed system by stating something like:

du($path)

Returns the disk usage of $path as given by the du command on the target system.

And perhaps even in the module description:

DESCRIPTION

With this module you can do file system tasks like creating directories, deleting or moving files, and more. The functions are often named and behave similarly as the well-known Linux commands.

What do you think? Would something like that have helped you better understand what the du() function and/or the Rex::Commands::Fs module does?

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /