cksum
cksum | |
---|---|
![]() Example usage of cksum to calculate CRC checksum and byte counts of a file | |
Operating system | Unix, Unix-like |
Platform | Cross-platform |
Type | Command |
cksum
is a shell command for generating a checksum for a file or stream of data. The command reports the 32-bit cyclic redundancy check (CRC) checksum and byte count for each file specified in the command-line arguments or for standard input if no arguments provided.[1] The CRC value is different from the CRC-32 used with a zip file, PNG or zlib.[2]
The command can be used to verify that files transferred (possibly via unreliable means) arrived intact.[1] However, the checksum calculated 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 on Unix and Unix-like system and via UnxUtils.[3] The GNU Coreutils implementaion provides additional checksum algorithms via -a
option, as an extension beyond POSIX.[1]
The standard command, as found on most Unix and Unix-like operating systems (including Linux, *BSD,[4][5][6] macOS, and Solaris[7]) uses a CRC algorithm based on the ethernet standard frame check[8] 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]
The command 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.[8]
Examples
[edit]The following calculates the checksum for file test.txt. The checksum is 4038471504 and the file size in is 75 bytes.
$ cksum test.txt
4038471504 75 test.txt
See also
[edit]- Cyclic redundancy check – Error-detecting code for detecting data changes
- GNU Core Utilities – Collection of standard, Unix-based utilities from GNU
- List of POSIX commands
- md5sum – Software that verifies hashes
- sum (Unix) – Unix command
References
[edit]- ^ a b c "cksum: Print CRC checksum and byte counts". gnu.org. Retrieved 2015-07-05.
- ^ "Catalogue of parametrised CRC algorithms". reveng.sourceforge.io.
- ^ "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.
- ^ "cksum(1)". www.freebsd.org. April 28, 1995. Retrieved 2023-01-07.
- ^ "cksum(1) - NetBSD Manual Pages". man.netbsd.org. December 14, 2019. Retrieved 2023-01-07.
- ^ "cksum(1) - OpenBSD manual pages". man.openbsd.org. August 4, 2022. Retrieved 2023-01-07.
- ^ "cksum - man pages section 1: User Commands". docs.oracle.com. Retrieved 2023-01-07.
- ^ a b "cksum". pubs.opengroup.org.
External links
[edit]- The Single UNIX Specification, Version 5 from The Open Group – Shell and Utilities Reference,
- cksum – GNU Core Utilities
- FreeBSD General Commands Manual –
- Linux User Manual – User Commands –