cksum
{{Short description|Unix command}}
{{lowercase title}}
{{Infobox software
| name = cksum
| logo =
| screenshot = Cksum-example-command.gif
| screenshot size =
| caption = Example usage of cksum
to calculate CRC checksum and byte counts of a file
| author =
| developer =
| released =
| latest release version =
| latest release date =
| operating system = Unix, Unix-like
| platform = Cross-platform
| genre = Command
| license =
| website =
}}
cksum
is a command in Unix and Unix-like operating systems that generates a checksum value for a file or stream of data. The cksum command reads each file given in its arguments, or standard input if no arguments are provided, and outputs the file's 32-bit cyclic redundancy check (CRC) checksum and byte count. The CRC output by cksum is different from the CRC-32 used in zip, PNG and zlib.{{Cite web |title=Catalogue of parametrised CRC algorithms |url=https://reveng.sourceforge.io/crc-catalogue/all.htm |website=reveng.sourceforge.io |language=en}}
The cksum
command can be used to verify that files transferred by unreliable means arrived intact.{{cite web |title=cksum: Print CRC checksum and byte counts |url=https://www.gnu.org/software/coreutils/manual/html_node/cksum-invocation.html |access-date=2015-07-05 |website=gnu.org}} However, the CRC checksum calculated by the cksum
command is not cryptographically secure: While it guards against accidental corruption (it is unlikely that the corrupted data will have the same checksum as the intended data), it is not difficult for an attacker to deliberately corrupt the file in a specific way that its checksum is unchanged. Unix-like systems typically include other commands for cryptographically secure checksums, such as sha256sum.
The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.{{Cite web|url=http://unxutils.sourceforge.net/|title=Native Win32 ports of some GNU utilities|website=unxutils.sourceforge.net}}
Latest GNU Coreutils cksum provides additional checksum algorithms via -a option, as an extension beyond POSIX.
Interoperability
The standard cksum
command, as found on most Unix and Unix-like operating systems (including Linux, *BSD,{{Cite web |date=April 28, 1995 |title=cksum(1) |url=https://www.freebsd.org/cgi/man.cgi?query=cksum&sektion=1 |access-date=2023-01-07 |website=www.freebsd.org}}{{Cite web |date=December 14, 2019 |title=cksum(1) - NetBSD Manual Pages |url=https://man.netbsd.org/cksum.1 |access-date=2023-01-07 |website=man.netbsd.org}}{{Cite web |date=August 4, 2022 |title=cksum(1) - OpenBSD manual pages |url=https://man.openbsd.org/cksum.1 |access-date=2023-01-07 |website=man.openbsd.org}} macOS, and Solaris{{Cite web |title=cksum - man pages section 1: User Commands |url=https://docs.oracle.com/cd/E88353_01/html/E37839/cksum-1g.html |access-date=2023-01-07 |website=docs.oracle.com}}) uses a CRC algorithm based on the ethernet standard frame check and is therefore interoperable between implementations. This is in contrast to the sum command, which is not as interoperable and not compatible with the CRC-32 calculation. On Tru64 operating systems, the cksum
command returns a different CRC value, unless the environment variable CMD_ENV
is set to xpg4
.{{Citation needed|date=January 2023}}
Algorithm
cksum
uses the generator polynomial 0x04C11DB7 and appends to the message its length in little endian representation. That length has null bytes trimmed on the right end.{{Cite web|url=https://pubs.opengroup.org/onlinepubs/9699919799/utilities/cksum.html|title=cksum|website=pubs.opengroup.org}}
Syntax
cksum [FILE]...
cksum [OPTION]
Usage example
$ cksum test.txt
4038471504 75 test.txt
where 4038471504
represents the checksum value and 75
represents the file size of test.txt
.
See also
References
{{Reflist}}
External links
{{Wikibooks|Guide to Unix|Commands}}
- {{man|cu|cksum|SUS}}
- [https://www.gnu.org/software/coreutils/manual/html_node/cksum-invocation.html cksum] – GNU Core Utilities
- {{man|1|cksum|FreeBSD}}
- {{man|1|cksum|Linux}}
{{Unix commands}}
{{Core Utilities commands}}