LinuxCommandLibrary

cksum

Verify data integrity using checksums

TLDR

Display a 32-bit checksum, size in bytes and filename

$ cksum [path/to/file]
copy

SYNOPSIS

cksum [OPTION]... [FILE]...

PARAMETERS

FILE
    One or more files to be checksummed. If no FILE is specified, or if FILE is '-', cksum reads from standard input.

--help
    Display a help message and exit.

--version
    Output version information and exit.

DESCRIPTION

The cksum command computes a Cyclic Redundancy Check (CRC) checksum for each specified file and displays the checksum, the number of bytes in the file, and the filename.

It is primarily used to detect accidental data corruption during transmission or storage. By comparing the cksum output of a file at different times or locations, users can verify its integrity.

The algorithm used is a 32-bit CRC, specified by POSIX, which makes it standardized across different Unix-like systems. For each file, cksum prints a line containing the calculated checksum, the file size in bytes, and the original filename. If no files are specified, it reads from standard input.

It's important to note that cksum is not cryptographically secure. It is suitable for detecting random errors but cannot protect against deliberate tampering, as collisions (different files producing the same checksum) can be found relatively easily. For strong cryptographic integrity checks, commands like md5sum or sha256sum should be used.

CAVEATS

cksum is not cryptographically secure. It is designed to detect accidental data corruption, not malicious tampering. Collisions (different data producing the same checksum) are relatively easy to find.

While the CRC-32 algorithm is specified by POSIX, subtle variations in implementation (e.g., polynomial, initial value, XOR output) can theoretically exist, though for the `cksum` utility as part of GNU Core Utilities, it's generally consistent.

OUTPUT FORMAT

For each input FILE, cksum outputs a single line in the format: CHECKSUM SIZE FILENAME.

When reading from standard input, FILENAME is replaced by a hyphen (-).

Example: cksum myfile.txt might output 3810234567 1234 myfile.txt, where 3810234567 is the checksum and 1234 is the file size in bytes.

COMMON USE CASES

  • Verifying file integrity after downloading: Compare the checksum provided by the source with the one computed locally.
  • Checking for accidental changes in configuration files or other critical data.
  • Simple data validation within scripts or automated processes.

HISTORY

The cksum command is part of the GNU Core Utilities and is standardized by POSIX.1-2001 and later versions. It evolved from earlier Unix sum commands to provide a more portable and consistent checksum calculation across different Unix-like systems. Its primary advantage over the older sum command was the standardization of the 32-bit CRC algorithm, ensuring that the same file would yield the same checksum result on different compliant systems.

SEE ALSO

sum(1), md5sum(1), sha1sum(1), sha256sum(1), sha512sum(1)

Copied to clipboard