sum
Calculate checksum and block count of files
TLDR
Compute a checksum with BSD-compatible algorithm and 1024-byte blocks
Compute a checksum with System V-compatible algorithm and 512-byte blocks
SYNOPSIS
sum [OPTION]... [FILE]...
PARAMETERS
-r
Use the BSD checksum algorithm (if available).
-s, --sysv
Use the System V checksum algorithm.
--help
Display help message and exit
--version
Output version information and exit
FILE
The file to calculate the checksum of. If no file is specified, or if FILE is '-', read from standard input.
DESCRIPTION
The sum command in Linux is a utility used to calculate a checksum and block count for a file. It serves primarily for basic file integrity verification. Two algorithms are available depending on the system: the historical System V checksum algorithm, and the BSD checksum algorithm. The default algorithm used, and the format of the output, may vary across different Unix-like systems.
While sum provides a simple way to check for data corruption, its checksum algorithms are relatively weak and not cryptographically secure. Modern tools like md5sum, sha256sum, or cksum are preferred for stronger checksum verification, particularly when security is important. Sum finds occasional use in scripts or simple automated tasks where a basic integrity check suffices.
The block count provided refers to the number of 512-byte blocks the file occupies, useful in specific low-level contexts.
CAVEATS
The checksum algorithms used by 'sum' are weak and should not be used for security-sensitive applications. Use stronger algorithms such as SHA-256 or MD5 instead. Output format may vary across systems.
OUTPUT FORMAT
The output of sum typically consists of the checksum, the number of 512-byte blocks, and the filename. If no filename is provided, it processes standard input and displays only the checksum and block count.
EXIT STATUS
The sum command typically returns an exit status of 0 upon successful completion, and a non-zero exit status if an error occurs (e.g., if a specified file cannot be opened).
HISTORY
The sum command has been a part of Unix systems for a long time, dating back to early versions of Unix. It originally served as a straightforward tool for verifying file integrity. The two checksum algorithms, System V and BSD, reflect different historical developments of Unix. Over time, more robust checksum tools have been developed, but 'sum' remains in use due to its simplicity and availability.