I sometimes wish human-readable du -h
option to be more fine-grained while still human-readable.
Instead of showing:
14G
it would show something like:
14G 236M 788k 110b
Is there an easy / straightforward / standard way to get this?
I sometimes wish human-readable du -h
option to be more fine-grained while still human-readable.
Instead of showing:
14G
it would show something like:
14G 236M 788k 110b
Is there an easy / straightforward / standard way to get this?
Well, there seems to be no easy / straightforward / standard way to do this yet.
Alternative options are (credits to ridgy's, Carpette's, Weijun Zhou's and drl's comments :):
write a dedicated small converter utility in bash/awk/python/etc. so that:
$ echo "789456" | utility
770K 976o
Then pipe it to convert du
output. You can inspire from this related
question. If it runs well, it could also parse the output of any command piped to it like:
$ du -s | utility
$ ls -la | utility
You can even alias it forever on you machine to:
duH() du -s $@ | utility
du -s
, du -hc
, du
--si
). Any command output (ls -lah
, rsync
) has to be parsed for
finding digits strings meant to represent bytes and transformed without
breaking the layout.get into coreutils
source code and add a new relevant option suiting your
needs. You'll probably have to have a glance at ./lib/human.c
. Then once
modified, it'll be a matter of ./configure
, make
, make install
so the
du
on your machine will now have this option implemented.
du
?C
code and understand it first
not to break it. You'll have to reinstall your own version of coreutils
on any
machine you need to use it.For now, I'm not getting into this soon. Anyway, feel free to post here your own pieces of solutions or alternatives workarounds as they come :)
o
in110o
? – Arkadiusz Drabczyk Dec 27 '17 at 16:06awk
function and pipedu
output to it.. why not. Thanks :) – iago-lito Dec 27 '17 at 16:29du
andawk
in a shell function calleddu
– Weijun Zhou Dec 27 '17 at 16:37du
:du -hs
,du -hc
,du --si
, etc. This is why I think of modifying the source might be easier. – ridgy Dec 27 '17 at 17:06coreutils
then? – iago-lito Dec 27 '17 at 17:17./lib/human.c
(and probably./lib/human.h
) as this is the function library used, and then do aconfigure
andmake
. All those coreutils now will have that human readable format you defined, but as long as you do nomake install
that doesn't harm. – ridgy Dec 27 '17 at 20:02human.h
for the new buffer lengthLONGEST_HUMAN_READABLE
, and then either modify after targetdo_grouping
or the full functionhuman_readable
. – ridgy Dec 27 '17 at 20:18coreutils
releases? – iago-lito Dec 27 '17 at 20:23ls -la | new_utility
.. and in the same pipeline, how would we discriminate between filesizes and filecounts? – iago-lito Dec 28 '17 at 09:09