Skip to content

What is sum Linux command?

The Linux sum command calculates and prints the checksum and block counts of a file. It can be used to verify the integrity of files and detect any changes or corruption.

sum Syntax:

Terminal window
sum [OPTION]... [FILE]...

sum Options:

OptionDescription
-sPrint only the sum of data
-rPrint in reverse order
-0End each output line with ASCII NUL

Parameters:

ParameterDescription
FILESpecify the paths to the files to sum

sum Command Usage Examples:

Check the Checksum of a File

Terminal window
sum file.txt

Calculates and displays the checksum of the file “file.txt”.

Verify Multiple Files Checksum

Terminal window
sum file1.txt file2.txt file3.txt

Calculates and displays the checksum of multiple files “file1.txt”, “file2.txt”, and “file3.txt”.

Compare Checksums between Two Files

Terminal window
sum file1.txt file2.txt

Calculates and displays the checksums of “file1.txt” and “file2.txt” for comparison.

Redirect Sum Output to a File

Terminal window
sum file.txt > checksum.txt

Calculates and saves the checksum of “file.txt” in a separate file named “checksum.txt”.

Display Checksum in Binary/Hexadecimal Form

Terminal window
sum -r file.txt

Calculates and displays the checksum of “file.txt” in binary and hexadecimal form.

How do I use sum in Linux?

To use the sum command in bash, execute the following command:

Terminal window
sum file.txt

How can I output the checksum in a specific format with sum?

To output the checksum in a specific format, use the following command:

Terminal window
sum --format=null file.txt

How can I display the help information for sum command?

To display the help information for the sum command, use the following command:

Terminal window
sum --help

How do I verify the integrity of a file using sum?

To verify the integrity of a file using sum, execute the following command:

Terminal window
sum -c checksum.txt

How to calculate the checksum of multiple files with sum?

To calculate the checksum of multiple files, use the following command:

Terminal window
sum file1.txt file2.txt

Can I ignore warnings when using sum in Linux?

To ignore warnings when using sum, you can use the -w flag in the command. For example:

Terminal window
sum -w file.txt

How to specify a different hashing algorithm with sum?

To specify a different hashing algorithm, use the -a option in the command. For example, to use SHA256, run:

Terminal window
sum -a SHA256 file.txt

Is there a way to only display the checksum without the filename using sum?

To display only the checksum without the filename, use the -t option in the command. For example:

Terminal window
sum -t file.txt

Applications of the sum command

  • Checking for changes in files
  • Verifying data integrity