Cksum

Last updated
cksum
Operating system Unix, Unix-like
Platform Cross-platform
Type Command

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. [1] The CRC output by cksum is different from the CRC-32 used in zip, PNG and zlib. [2]

Contents

The cksum command can be used to verify that files transferred by unreliable means arrived intact. [1] 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. [3]

Latest GNU Coreutils cksum provides additional checksum algorithms via -a option, as an extension beyond POSIX. [1]

Interoperability

The standard cksum 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 ]

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. [8]

Syntax

cksum[FILE]... cksum[OPTION]

Usage example

$ cksumtest.txt 4038471504 75 test.txt

where 4038471504 represents the checksum value and 75 represents the file size of test.txt.

See also

Related Research Articles

gzip GNU file compression/decompression tool

gzip is a file format and a software application used for file compression and decompression. The program was created by Jean-loup Gailly and Mark Adler as a free software replacement for the compress program used in early Unix systems, and intended for use by GNU. Version 0.1 was first publicly released on 31 October 1992, and version 1.0 followed in February 1993.

In computing, tar is a computer software utility for collecting many files into one archive file, often referred to as a tarball, for distribution or backup purposes. The name is derived from "tape archive", as it was originally developed to write data to sequential I/O devices with no file system of their own, such as devices that use magnetic tape. The archive data sets created by tar contain various file system parameters, such as name, timestamps, ownership, file-access permissions, and directory organization. POSIX abandoned tar in favor of pax, yet tar sees continued widespread use.

ls Command to list files and directories in Unix and Unix-like operating systems

In computing, ls is a command to list computer files and directories in Unix and Unix-like operating systems. It is specified by POSIX and the Single UNIX Specification.

chown Command used on Unix-like systems to change the owner of a file

The command chown, an abbreviation of change owner, is used on Unix and Unix-like operating systems to change the owner of file system files and directories. Unprivileged (regular) users who wish to change the group membership of a file that they own may use chgrp.

The Unix command su, which stands for 'substitute user', is used by a computer user to execute commands with the privileges of another user account. When executed it invokes a shell without changing the current working directory or the user environment.

md5sum is a computer program that calculates and verifies 128-bit MD5 hashes, as described in RFC 1321. The MD5 hash functions as a compact digital fingerprint of a file. As with all such hashing algorithms, there is theoretically an unlimited number of files that will have any given MD5 hash. However, it is very unlikely that any two non-identical files in the real world will have the same MD5 hash, unless they have been specifically created to do so.

dd is a command-line utility for Unix, Plan 9, Inferno, and Unix-like operating systems and beyond, the primary purpose of which is to convert and copy files. On Unix, device drivers for hardware and special device files appear in the file system just like normal files; dd can also read and/or write from/to these files, provided that function is implemented in their respective driver. As a result, dd can be used for tasks such as backing up the boot sector of a hard drive, and obtaining a fixed amount of random data. The dd program can also perform conversions on the data as it is copied, including byte order swapping and conversion to and from the ASCII and EBCDIC text encodings.

tr (Unix) Unix text formatting utility

tr is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. It is an abbreviation of translate or transliterate, indicating its operation of replacing or removing specific characters in its input data set.

wc (Unix) Unix command utility

wc is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. The program reads either standard input or a list of computer files and generates one or more of the following statistics: newline count, word count, and byte count. If a list of files is provided, both individual file and total statistics follow.

df (Unix) Standard Unix command

df is a standard Unix command used to display the amount of available disk space for file systems on which the invoking user has appropriate read access. df is typically implemented using the statfs or statvfs system calls.

cmp (Unix)

In computing, cmp is a command-line utility on Unix and Unix-like operating systems that compares two files of any type and writes the results to the standard output. By default, cmp is silent if the files are the same; if they differ, the byte and line number at which the first difference occurred is reported. The command is also available in the OS-9 shell.

diff3 is a Unix utility to compare three files and show any differences among them. diff3 can also merge files, implementing a three-way merge.

tail is a program available on Unix, Unix-like systems, FreeDOS and MSX-DOS used to display the tail end of a text file or piped data.

In computing, sleep is a command in Unix, Unix-like and other operating systems that suspends program execution for a specified time.

sum is a legacy utility available on some Unix and Unix-like operating systems. This utility outputs a 16-bit checksum of each argument file, as well as the number of blocks they take on disk. Two different checksum algorithms are in use. POSIX abandoned sum in favor of cksum.

In computing, which is a command for various operating systems used to identify the location of executables. The command is available in Unix and Unix-like systems, the AROS shell, for FreeDOS and for Microsoft Windows. The functionality of the which command is similar to some implementations of the type command. POSIX specifies a command named command that also covers this functionality.

The SYSV checksum algorithm was a commonly used, legacy checksum algorithm. It has been implemented in UNIX System V and is also available through the sum command line utility.

The csplit command in Unix and Unix-like operating systems is a utility that is used to split a file into two or more smaller files determined by context lines.

fold is a Unix command used for making a file with long lines more readable on a limited width computer terminal by performing a line wrap.

On Unix-like computer systems, seq is a utility for generating a sequence of numbers.

References

  1. 1 2 3 "cksum: Print CRC checksum and byte counts". gnu.org. Retrieved 2015-07-05.
  2. "Catalogue of parametrised CRC algorithms". reveng.sourceforge.io.
  3. "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.
  4. "cksum(1)". www.freebsd.org. April 28, 1995. Retrieved 2023-01-07.
  5. "cksum(1) - NetBSD Manual Pages". man.netbsd.org. December 14, 2019. Retrieved 2023-01-07.
  6. "cksum(1) - OpenBSD manual pages". man.openbsd.org. August 4, 2022. Retrieved 2023-01-07.
  7. "cksum - man pages section 1: User Commands". docs.oracle.com. Retrieved 2023-01-07.
  8. 1 2 "cksum". pubs.opengroup.org.