Bug 1582165
| Summary: | Enhancements – Accuracy, Documentation, Conventions, Basic units of measure | ||
|---|---|---|---|
| Product: | [Fedora] Fedora | Reporter: | ricky.tigg |
| Component: | coreutils | Assignee: | Kamil Dudka <kdudka> |
| Status: | CLOSED WONTFIX | QA Contact: | Fedora Extras Quality Assurance <extras-qa> |
| Severity: | low | Docs Contact: | |
| Priority: | unspecified | ||
| Version: | 28 | CC: | admiller, jamartis, jarodwilson, kdudka, kzak, ooprala, ovasik, p, skisela, twaugh |
| Target Milestone: | --- | ||
| Target Release: | --- | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | If docs needed, set a value | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2018-05-25 08:44:20 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
|
Description
ricky.tigg
2018-05-24 12:14:27 UTC
Thanks for the suggestion! Unfortunately, I do not think we can change the output format without breaking compatibility with existing scripts that use the current output format. If you need to get more precise results, or results in any different format, I would suggest to run df _without_ the -h option and post-process the output of df by an awk script. I would also suggest to take further enhancement proposals to the upstream mailing list, which has wider audience and it is thus more appropriate to discuss such proposals: https://www.gnu.org/software/coreutils/coreutils.html#help Is then expression 'df | awk '<pattern> {<action>}' /output-file' the right interpretation?
You can start with something like this:
$ df | awk '{ if (NR > 1) printf("%-30s %8.2f GiB %8.2f GiB %8.2f GiB %7.2f %% %s\n", $1, $2/(2**20), $3/(2**20), $4/(2**20), 100.0*$3/$2, $6) }'
... which prints the following on my system:
udev 0.01 GiB 0.00 GiB 0.01 GiB 0.04 % /dev
/dev/mapper/kdudka--nb-root 458.93 GiB 341.97 GiB 115.16 GiB 74.51 % /
tmpfs 1.55 GiB 0.00 GiB 1.55 GiB 0.07 % /run
shm 7.77 GiB 0.04 GiB 7.74 GiB 0.47 % /dev/shm
cgroup_root 0.01 GiB 0.00 GiB 0.01 GiB 0.00 % /sys/fs/cgroup
/dev/mapper/kdudka--nb-root 458.93 GiB 341.97 GiB 115.16 GiB 74.51 % /home/kdudka
/dev/mapper/kdudka--nb-root 458.93 GiB 341.97 GiB 115.16 GiB 74.51 % /tmp
/dev/mapper/kdudka--nb-root 458.93 GiB 341.97 GiB 115.16 GiB 74.51 % /usr/portage
/dev/mapper/kdudka--nb-root 458.93 GiB 341.97 GiB 115.16 GiB 74.51 % /usr/src
/dev/mapper/kdudka--nb-root 458.93 GiB 341.97 GiB 115.16 GiB 74.51 % /var/cache
/dev/mapper/kdudka--nb-root 458.93 GiB 341.97 GiB 115.16 GiB 74.51 % /var/lib/docker
/dev/mapper/kdudka--nb-root 458.93 GiB 341.97 GiB 115.16 GiB 74.51 % /var/lib/libvirt
/dev/mapper/kdudka--nb-root 458.93 GiB 341.97 GiB 115.16 GiB 74.51 % /var/tmp
none 7.77 GiB 0.00 GiB 7.77 GiB 0.00 % /run/user/1024
/dev/mapper/data 916.77 GiB 390.83 GiB 479.35 GiB 42.63 % /home/share
The less I can do is to start investigating how to use the awk tool starting at the GNU version of the AWK text processing utility 'man gawk', and figuring out the meaning of the above mentioned input command. Pádraig Brady suggested to use numfmt to format the numbers at upstream ML: $ df -B1 | numfmt --header --field=2-4 --to=iec --format %.2f https://lists.gnu.org/archive/html/coreutils/2018-05/msg00063.html I figured out all of the command meanings except expressions '"%-30s', '2**20'. Suggested command in Comment 5 illustrates presently common mistaken use of convention mentioned in Description and that command announced in Comment 3 did achieve to overcome. Percentage too remained with a non-adequate accuracy. $ df -B1 | numfmt --header --field=2-4 --to=iec --format %.2f Filesystem 1B-blocks Used Available Use% Mounted on devtmpfs 1.89G 0.00 1.89G 0% /dev ... (In reply to ricky.tigg from comment #6) > I figured out all of the command meanings except expressions '"%-30s', > '2**20'. '%-30s' is a printf conversion for left-aligned string of size 30 chars. '2**20' is an awk expression for 2^20, which is equal to 1048576. > Suggested command in Comment 5 illustrates presently common mistaken use of > convention mentioned in Description and that command announced in Comment 3 > did achieve to overcome. Percentage too remained with a non-adequate > accuracy. You can even combine both the approaches together: $ df -B1 | awk '{ if (NR > 1) printf("%-30s %12d %12d %12d %7.2f%% %s\n", $1, $2, $3, $4, $3?100.0*$3/$2:0, $6) }' | numfmt --field=2-4 --to=iec --format %.2f Thank you. 'df -B1' piped twice. With current parameters 'numfmt --field=2-4 --to=iec --format %.2f' degraded well achieved command output in Comment 3: '1,81G', '0,00', once more '0.00%'. $ df -B1 | awk '{ if (NR > 1) printf("%-30s %12d %12d %12d %7.2f%% %s\n", $1, $2, $3, $4, $3?100.0*$3/$2:0, $6) }' | numfmt --field=2-4 --to=iec --format %.2f devtmpfs 1,81G 0,00 1,81G 0.00% /dev |