How to use the command `sum` (with examples)
The sum
command is used to compute checksums and the number of blocks for a file. It is a predecessor to the more modern cksum
command. Checksums are used to verify the integrity of a file by generating a unique hash value based on the file’s contents. The sum
command provides two different algorithms for generating checksums and allows you to specify the size of the blocks used in the computation.
Use case 1: Compute a checksum with BSD-compatible algorithm and 1024-byte blocks
Code:
sum path/to/file
Motivation: Computing a checksum with the BSD-compatible algorithm and 1024-byte blocks may be necessary for compatibility reasons. Some older operating systems and applications may still rely on this algorithm.
Explanation:
sum
: The command name.path/to/file
: The path to the file for which you want to compute the checksum.
Example output:
4377 1 path/to/file
In the example output, 4377
represents the checksum value, 1
represents the number of blocks, and path/to/file
is the path to the file.
Use case 2: Compute a checksum with System V-compatible algorithm and 512-byte blocks
Code:
sum --sysv path/to/file
Motivation: Computing a checksum with the System V-compatible algorithm and 512-byte blocks may be necessary for compatibility reasons. Some older operating systems and applications may still rely on this algorithm.
Explanation:
sum
: The command name.--sysv
: This option tells the command to use the System V-compatible algorithm.path/to/file
: The path to the file for which you want to compute the checksum.
Example output:
26795 2 path/to/file
In the example output, 26795
represents the checksum value, 2
represents the number of blocks, and path/to/file
is the path to the file.
Conclusion:
The sum
command is a useful tool for computing checksums and the number of blocks for a file. It allows you to choose between different algorithms and block sizes, making it versatile for various compatibility requirements. Whether you need to compute checksums with a BSD-compatible or System V-compatible algorithm, the sum
command has got you covered.