sum - Calculate and display checksums and block counts

Format

sum [-ciprtT] [file...]

The sum utility is fully supported for compatibility with older UNIX systems. However, use cksum utility because it may provide greater functionality and is considered the standard for portable UNIX applications as defined by POSIX.2 IEEE standard 1003.2-1992.

Description

sum calculates and displays a checksum for each input file. A checksum is an error-checking technique used by many programs as a quick way to compare files that have been moved from one location to another to ensure that no data has been lost. It also displays the number of 512-byte blocks in each file.

If you do not specify any files, or if you specify - as the file name, sum reads standard input (stdin).

sum differs from cksum only in the format of the output.
  • When _UNIX03 is YES, the output of sum has the space-separated form:
    checksum blockcount filename
  • When _UNIX03 is unset or not YES, the output of sum has the tab-separated form:
    checksum    blockcount   filename

If a file operand is not specified, the path name and its leading white space is omitted.

Read error messages are controlled by the _UNIX03 variable.
  • If sum fails with a read error and _UNIX03 is YES, it sends a diagnostic message to standard error, and will not show a checksum for that file.
  • If _UNIX03 is unset or not YES, it displays the checksum up to that point and marks the output line with FSUM6199 [read].
sum continues processing files in either case.

All other error messages are sent to standard error.

Options

sum can calculate checksums in a variety of ways. The default checksum algorithm produces a 16-bit unsigned integer resulting from the arithmetic addition of each input byte. This checksum algorithm is not sensitive to byte order.

-c
Uses a standard 16-bit cyclical redundancy check (CRC-16).
-i
Uses the CCITT standard cyclic redundancy check (CRC-CCITT). Data communications network protocols often use a cyclic redundancy check to ensure proper transmission. This algorithm is more likely to produce a different sum for inputs which differ only in byte order.
-p
Uses the POSIX.2 checksum algorithm.
-r
Enables the use of an alternate checksum algorithm which has the advantage of being sensitive to byte order.
-t
Produces a line containing the total number of blocks of data read, as well as the checksum of the concatenation of the input files.
-T
Enables the automatic conversion of tagged files.

Environment variables

  • _UNIX03

Localization

sum uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
  • LC_TYPE
  • NLSPATH

Exit values

0
Successful completion.
1
Failure due to any of the following reasons:
  • Inability to open input file.
  • Error reading the input file.
  • Error turning off the automatic conversion of the input file.
2
Unknown command-line option.

Portability

The default checksum algorithm is compatible with UNIX System V.2 and later. The -r algorithm is also available on UNIX System V.2 and is the default algorithm for Berkeley and Version 7. The -c, -i, and -t options are not available under UNIX.

Related information

cmp, cksum, diff, ls, wc