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]...
Display CRC checksum and block count for each FILE (stdin if none).

PARAMETERS

-a TYPE, --algorithm=TYPE
    use hash algorithm TYPE (e.g., crc, md5, sha256); see cksum.table

-b, --binary
    read files in binary mode (default on DOS/Windows)

-t, --text
    read files in text mode (default)

--tag
    use BSD-style checksum format

-z, --zero
    end lines with NUL (not newline), for xargs -0

--help
    print help and exit

--version
    print version and exit

DESCRIPTION

cksum is a Unix command-line utility that calculates and prints the Cyclic Redundancy Check (CRC) checksum (default: POSIX.2 CRC-32), the number of 512-byte blocks, and the filename for each input file. It is designed for verifying data integrity by detecting accidental errors or changes, such as during file transfers or backups.

Usage involves specifying one or more files or piping data to stdin (where no filename is output). The GNU Coreutils version extends functionality with support for multiple hash algorithms (e.g., MD5, SHA-256) via -a, binary/text mode adjustments, and alternative output formats.

Output example: 3979395584 1 filename, where the first field is the checksum, second is blocks, and third is the filename.

It excels in scripts for batch integrity checks due to its speed and low overhead on large files. However, CRC is probabilistic error detection, not proof against intentional tampering.

CAVEATS

CRC is for error detection, not security; vulnerable to collisions. Use SHA for stronger integrity.

OUTPUT FORMAT

CHECKSUM BLOCKS FILENAME
(stdin: CHECKSUM BLOCKS only)

EXAMPLE

cksum /etc/passwd
1265572197 21 /etc/passwd
echo 'test' | cksum
2867761264 1

HISTORY

Originated in SVR4 Unix (1989); standardized in POSIX.1-2008. GNU Coreutils added multi-algo support in v8.28 (2017).

SEE ALSO

md5sum(1), sha256sum(1), sum(1), b2sum(1)

Copied to clipboard