Overview
The sum command calculates the checksum and block count of a specified file and outputs it to standard output. These values can be used to quickly verify if the file's content has changed. By default, it calculates using 512-byte blocks in BSD-compatible mode.
Key Features
- Calculates a 16-bit checksum of the file
- Calculates the number of blocks in the file (default 512 bytes or 1KB)
- Provides a simple way to check file integrity and detect changes
- Supports both BSD and System V compatible modes
Key Options
The sum command offers a few options to change the checksum calculation method.
Checksum Modes
Generated command:
Try combining the commands.
Description:
`sum` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Learn various ways to calculate file checksums and block counts using the sum command.
Basic Checksum Calculation (BSD Mode)
echo 'Hello World' > testfile.txt
sum testfile.txt
Calculates the default (BSD) checksum and block count for a file. (Create testfile.txt first)
System V Mode Checksum Calculation
sum -s testfile.txt
Calculates the checksum and block count for a file using System V compatible mode.
Calculating Checksums for Multiple Files
echo 'Another file' > anotherfile.txt
sum testfile.txt anotherfile.txt
Calculates checksums for multiple files simultaneously.
Calculating Checksum from Standard Input
echo 'Data from stdin' | sum
Calculates the checksum for data piped from standard input.
Tips & Warnings
While the sum command is suitable for simple use cases, it is recommended to use more robust tools for modern file integrity verification.
Security Warning
The 16-bit checksum generated by sum has a high probability of collisions, meaning two files with different content can have the same checksum. Therefore, it is not suitable for verifying the integrity of critical data.
- Low Security: 16-bit checksums are vulnerable to collisions, making it difficult to detect malicious modifications.
- Limited Use: Primarily used for non-security-critical purposes, such as quickly checking for changes in files during development.
Alternative Commands
For more robust and secure file integrity verification, it is recommended to use the following commands:
- md5sum: Calculates an MD5 hash (32 hexadecimal characters).
- sha1sum: Calculates a SHA-1 hash (40 hexadecimal characters).
- sha256sum: Calculates a SHA-256 hash (64 hexadecimal characters).
- cksum: Calculates a CRC32 checksum. It is more robust than sum but less secure than md5/sha variants.
Understanding Block Size
The block count from the sum command is the file size divided by the block size. The BSD mode uses 512 bytes, and the System V mode uses 1024 bytes (1KB) as the basis.
- BSD Block: 512 bytes (default)
- System V Block: 1024 bytes (1KB)