NAME
sum —
compute legacy checksum
SYNOPSIS
sum |
[-rs] [file]… |
DESCRIPTION
Writes a legacy checksum of files (standard input stream "-", the default) to the standard output stream.
OPTIONS
-r- Output 3BSD sum. This is the default.
-s,--sysv- Output AT&T System III UNIX sum.
SEE ALSO
HISTORY
Appears in the first edition of the UNIX Programmer's Manual as sum(I):
NAMEsum -- sum fileSYNOPSISsum name
sum name1 ...Version 7 AT&T UNIX sees a rewrite in C: it now uses the standard input stream if no files are specified and an updated output format: the sum is zero-padded to 5 digits and immediately followed by the block count, space-padded to six digits (this does mean that a file at least 51.2MB in size would end up with no spaces between the sum and the block count, but is hardly a problem, as disk packs available for the PDP-11 were 10 megabytes in size at the very top end), followed by a space and filename, if more than one was specified, and a newline. The algorithm also changed, rotating the accumulator right by one bit before each addition.
It also uses
<stdio.h> and
getc(3), emulating the block count by dividing by
BUFSIZ (512), rounded up. This is the version
included in 3BSD, which, however, started to define
BUFSIZ to 1024 — this is the birth of this
implementation's default (-r) format (extended with
a fixed space and block count space-padded to a width of 5, for reasons
assumed obvious).
AT&T System III UNIX introduced
an alternative checksum algorithm, which first added all bytes into a 32-bit
accumulator, then reduced it twice to the sum of the the high and low words,
and a simple sum, space, block count format. The old algorithm (and format)
was available under -r, but in both cases the
filenames were written if any were specified. Additionally, both formats
continued to use BUFSIZ, which was still 512. The
default format is this implementation's -s.
In 4.4BSD, sum was
moved to old, and the legacy algorithms became
available under cksum -o
1|2, but algorithm
1 — 3BSD — had
lost its special formatting. Since 4.4BSD-Lite2,
sum is provided by
cksum.