[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Commands Reference, Volume 1

cksum Command

Purpose

Displays the checksum and byte count of a file.

Syntax

cksumFile ... ]

Description

The cksum command reads the files specified by the File parameter and calculates a 32-bit checksum Cyclic Redundancy Check (CRC) and the byte count for each file. If no files are specified, the cksum command reads standard input. The checksum, number of bytes, and file name are written to standard output. If standard input is used, the path name and leading space are omitted.

The cksum command can be used to compare a suspect file copied or communicated over noisy transmission lines against an exact copy of a trusted file. The comparison made by the cksum command may not be cryptographically secure. However, it is unlikely that an accidentally damaged file will produce the same checksum as the original file.

The cksum command uses a different algorithm to calculate the 32-bit checksum CRC than the sum command. The cksum command uses a CRC algorithm based on the Ethernet standard frame check. For more information on the Ethernet standard, see "Understanding DLCETHER Protocol Support" in AIX Communications Programming Concepts.

Note: The cksum command is POSIX 1003.2 compliant and the checksum produced is guaranteed to be calculated the same on all POSIX 1003.2 compliant systems.

The following generating polynomial defines CRC checksum encoding:

G(x) = x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1

The following procedure mathematically defines the CRC value corresponding to a given file:

  1. The n bits to be evaluated are considered to be the coefficients of a mod 2 polynomial M(x) of degree n-1. These n bits are the bits from the file. The most significant bit is the most significant bit of the first octet of the file. The last bit is the least significant bit of the last octet, padded with zero bits (if necessary) to achieve an integral number of octets, followed by one or more octets representing the length of the file as a binary value, least significant octet first. The smallest number of octets capable of representing this integer is used.
  2. M(x) is multiplied by x32 (that is, shifted left 32 bits) and divided by G(x) using mod 2 division, producing a remainder R(x) of degree 31.
  3. The coefficients of R(x) are considered to be a 32-bit sequence.
  4. The bit sequence is complemented, and the result is the CRC.

Exit Status

This command returns the following exit values:

0 All files were processed successfully.
>0 An error occurred.

Examples

To display the checksum and the size, in bytes, of file1 and file2 , enter:

cksum file1 file2

If the checksum of the file1 file is 3995432187 and contains 1390 bytes, and the checksum of the file2 file is 3266927833 and contains 20912 bytes, the cksum command displays:

3995432187       1390    file1
3266927833       20912   file2

Files

/usr/bin/cksum Contains the cksum command.

Related Information

The sum command, wc command.

File Systems Overview for System Management in AIX Version 4.3 System Management Guide: Operating System and Devices gives an explanation of what a file system is and why to use one.

Understanding DLCETHER Protocol Support in AIX Communications Programming Concepts provides information on the Ethernet standard.


[ Previous | Next | Contents | Glossary | Home | Search ]