Debian Codegraph @

docs/src/extensions.md

raw
1 <!-- spell-checker:ignore hhhhp armv7 cccccccccccccccccccccccccccccccdp ccccccccccccccd ccccccccccccccdp fffffffp -->
2
3 # Extensions over GNU
4
5 Though the main goal of the project is compatibility, uutils supports a few
6 features that are not supported by GNU coreutils. We take care not to introduce
7 features that are incompatible with the GNU coreutils. Below is a list of uutils
8 extensions.
9
10 ## General
11
12 GNU coreutils provides two ways to define short options taking an argument:
13
14 ```
15 $ ls -w 80
16 $ ls -w80
17 ```
18
19 We support a third way:
20
21 ```
22 $ ls -w=80
23 ```
24
25 With GNU coreutils, `--help` usually prints the help message and `--version` prints the version.
26 We also commonly provide short options: `-h` for help and `-V` for version.
27
28 ## `coreutils`
29
30 Our `coreutils` calls utility by `coreutils utility-name` and has `--list` to run against busybox test suite.
31 Our `coreutils` is called as `utility-name` if its binary name ends with `utility-name` to support prefixed names.
32 Longer name is prioritized e.g. `sum` with the prefix `ck` is called as `cksum`.
33
34 ## `base32/base64/basenc`
35
36 Just like on macOS, `base32/base64/basenc` provides `-D` to decode data.
37
38 ## `cp`
39
40 `cp` can display a progress bar when the `-g`/`--progress` flag is set.
41
42 ## `du`
43
44 `du` allows `birth` and `creation` as values for the `--time` argument to show the creation time. It
45 also provides a `-v`/`--verbose` flag.
46
47 ## `env`
48
49 GNU `env` allows the empty string to be used as an environment variable name.
50 This is unsupported by uutils, which will show a warning for any such
51 assignment.
52
53 `env` has an additional `-f`/`--file` flag that can
54 parse `.env` files and set variables accordingly. This feature is adopted from `dotenv` style
55 packages.
56
57 ## `expand`
58
59 `expand` offers the `-U`/`--no-utf8` option to interpret input files as 8-bit ASCII instead of UTF-8.
60
61 ## `fmt`
62
63 `fmt` has additional flags for prefixes: `-P`/`--skip-prefix`, `-x`/`--exact-prefix`, and
64 `-X`/`--exact-skip-prefix`. With `-m`/`--preserve-headers`, an attempt is made to detect and preserve
65 mail headers in the input. `-q`/`--quick` breaks lines more quickly. And `-T`/`--tab-width` defines the
66 number of spaces representing a tab when determining the line length.
67
68 ## `id`
69
70 `id` has three additional flags:
71 * `-P` displays the id as a password file entry
72 * `-p` makes the output human-readable
73 * `-A` displays the process audit user ID
74
75 ## `install`
76
77 `install` offers FreeBSD's `-U` unprivileged option to not change the owner, the group, or the file flags of the destination.
78
79 ## `ls`
80
81 GNU `ls` provides two ways to use a long listing format: `-l` and `--format=long`. We support a
82 third way: `--long`.
83
84 GNU `ls --sort=VALUE` only supports special non-default sort orders.
85 We support `--sort=name`, which makes it possible to override an earlier value.
86
87 ## `more`
88
89 We provide a simple implementation of `more`, which is not part of GNU
90 coreutils. We do not aim for full compatibility with the `more` utility from
91 `util-linux`. Features from more modern pagers (like `less` and `bat`) are
92 therefore welcomed.
93
94 ## `mv`
95
96 `mv` can display a progress bar when the `-g`/`--progress` flag is set.
97
98 ## `printf`
99
100 `printf` uses arbitrary precision decimal numbers to parse and format floating point
101 numbers. GNU coreutils uses `long double`, whose actual size may be [double precision
102 64-bit float](https://en.wikipedia.org/wiki/Double-precision_floating-point_format)
103 (e.g 32-bit arm), [extended precision 80-bit float](https://en.wikipedia.org/wiki/Extended_precision)
104 (x86(-64)), or
105 [quadruple precision 128-bit float](https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format) (e.g. arm64).
106
107 Practically, this means that printing a number with high precision will remain exact:
108 ```
109 printf "%.48f\n" 0.1
110 0.100000000000000000000000000000000000000000000000 << uutils on all platforms
111 0.100000000000000000001355252715606880542509316001 << GNU coreutils on x86(-64)
112 0.100000000000000000000000000000000004814824860968 << GNU coreutils on arm64
113 0.100000000000000005551115123125782702118158340454 << GNU coreutils on armv7 (32-bit)
114 ```
115
116 ### Hexadecimal floats
117
118 For hexadecimal float format (`%a`), POSIX only states that one hexadecimal number
119 should be present left of the decimal point (`0xh.hhhhp±d` [1]), but does not say how
120 many _bits_ should be included (between 1 and 4). On x86(-64), the first digit always
121 includes 4 bits, so its value is always between `0x8` and `0xf`, while on other
122 architectures, only 1 bit is included, so the value is always `0x1`.
123
124 However, the first digit will of course be `0x0` if the number is zero. Also,
125 rounding numbers may cause the first digit to be `0x1` on x86(-64) (e.g.
126 `0xf.fffffffp-5` rounds to `0x1.00p-1`), or `0x2` on other architectures.
127
128 We chose to replicate x86-64 behavior on all platforms.
129
130 Additionally, the default precision of the hexadecimal float format (`%a` without
131 any specifier) is expected to be "sufficient for exact representation of the value" [1].
132 This is not possible in uutils as we store arbitrary precision numbers that may be
133 periodic in hexadecimal form (`0.1 = 0xc.ccc...p-7`), so we revert
134 to the number of digits that would be required to exactly print an
135 [extended precision 80-bit float](https://en.wikipedia.org/wiki/Extended_precision),
136 emulating GNU coreutils behavior on x86(-64). An 80-bit float has 64 bits in its
137 integer and fractional part, so 16 hexadecimal digits are printed in total (1 digit
138 before the decimal point, 15 after).
139
140 Practically, this means that the default hexadecimal floating point output is
141 identical to x86(-64) GNU coreutils:
142 ```
143 printf "%a\n" 0.1
144 0xc.ccccccccccccccdp-7 << uutils on all platforms
145 0xc.ccccccccccccccdp-7 << GNU coreutils on x86-64
146 0x1.999999999999999999999999999ap-4 << GNU coreutils on arm64
147 0x1.999999999999ap-4 << GNU coreutils on armv7 (32-bit)
148 ```
149
150 We _can_ print an arbitrary number of digits if a larger precision is requested,
151 and the leading digit will still be in the `0x8`-`0xf` range:
152 ```
153 printf "%.32a\n" 0.1
154 0xc.cccccccccccccccccccccccccccccccdp-7 << uutils on all platforms
155 0xc.ccccccccccccccd00000000000000000p-7 << GNU coreutils on x86-64
156 0x1.999999999999999999999999999a0000p-4 << GNU coreutils on arm64
157 0x1.999999999999a0000000000000000000p-4 << GNU coreutils on armv7 (32-bit)
158 ```
159
160 ***Note: The architecture-specific behavior on non-x86(-64) platforms may change in
161 the future.***
162
163 ## `rm`
164
165 `rm` can display a progress bar when the `-g`/`--progress` flag is set.
166
167 ## `seq`
168
169 Unlike GNU coreutils, `seq` always uses arbitrary precision decimal numbers, no
170 matter the parameters (integers, decimal numbers, positive or negative increments,
171 format specified, etc.), so its output will be more correct than GNU coreutils for
172 some inputs (e.g. small fractional increments where GNU coreutils uses `long double`).
173
174 The only limitation is that the position of the decimal point is stored in a `i64`,
175 so values smaller than 10**(-2**63) will underflow to 0, and some values larger
176 than 10**(2**63) may overflow to infinity.
177
178 See also comments under `printf` for formatting precision and differences.
179
180 `seq` provides `-t`/`--terminator` to set the terminator character.
181
182 ## `sort`
183
184 When sorting with `-g`/`--general-numeric-sort`, arbitrary precision decimal numbers
185 are parsed and compared, unlike GNU coreutils that uses platform-specific long
186 double floating point numbers.
187
188 Extremely large or small values can still overflow or underflow to infinity or zero,
189 see note in `seq`.
190
191 ## `unexpand`
192
193 GNU `unexpand` provides `--first-only` to convert only leading sequences of blanks. We support a
194 second way: `-f` like busybox.
195
196 With `-U`/`--no-utf8`, you can interpret input files as 8-bit ASCII rather than UTF-8.
197
198 ## `uptime`
199
200 Similar to the proc-ps implementation and unlike GNU/Coreutils, `uptime` provides:
201 * `-s`/`--since` to show since when the system is up
202 * `-p`/`--pretty` to display uptime in a pretty-printed format