sum command in Linux with Examples
The sum command in Linux is used to calculate the checksum and block count of files. This command helps in verifying file integrity by comparing the calculated checksum with an expected value. The sum command can operate on one or more files, and when no file is specified, it reads from standard input.
Syntax
The general syntax for the sum command is as follows:
sum [OPTION]... [FILE]...
Basic Example
It will ask for the input of the file we want to calculate the checksum. In the following example, we calculate the checksum for "myfile.txt".

Key Options used with the sum command
1. sum -r
Uses the BSD algorithm, with 1K blocks. This is useful when working in environments that prefer BSD-style checksum algorithms.
Example:
sum -r myfile.txt

2. sum -s
Uses the System V algorithm, with 512-byte blocks. This option is commonly used in older systems that rely on the System V algorithm.
Example:
sum -s myfile.txt

3. sum --help
Displays help text with a list of all options and exits.
Example:
sum --help

4. sum --version
Shows version information of the sum command and exits.
sum --version

Option | Description |
---|---|
-r | Uses the BSD algorithm with 1K blocks. Suitable for environments that rely on the BSD-style checksum. |
-s | Uses the System V algorithm with 512-byte blocks. Useful for older systems with the System V algorithm. |
--help | Displays help text with a list of options. |
--version | Shows the version information of the sum command. |
Conclusion
The sum command is a simple yet powerful tool for verifying file integrity in Linux systems. By using options such as -r and -s, you can choose different algorithms and block sizes based on your requirements. Whether you're verifying file downloads or automating checksum verification, sum is an essential command to know.