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:
sum [OPTION]... [FILE]...sum Options:
| Option | Description |
|---|---|
| -s | Print only the sum of data |
| -r | Print in reverse order |
| -0 | End each output line with ASCII NUL |
Parameters:
| Parameter | Description |
|---|---|
| FILE | Specify the paths to the files to sum |
sum Command Usage Examples:
Check the Checksum of a File
sum file.txtCalculates and displays the checksum of the file “file.txt”.
Verify Multiple Files Checksum
sum file1.txt file2.txt file3.txtCalculates and displays the checksum of multiple files “file1.txt”, “file2.txt”, and “file3.txt”.
Compare Checksums between Two Files
sum file1.txt file2.txtCalculates and displays the checksums of “file1.txt” and “file2.txt” for comparison.
Redirect Sum Output to a File
sum file.txt > checksum.txtCalculates and saves the checksum of “file.txt” in a separate file named “checksum.txt”.
Display Checksum in Binary/Hexadecimal Form
sum -r file.txtCalculates 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:
sum file.txtHow can I output the checksum in a specific format with sum?
To output the checksum in a specific format, use the following command:
sum --format=null file.txtHow can I display the help information for sum command?
To display the help information for the sum command, use the following command:
sum --helpHow do I verify the integrity of a file using sum?
To verify the integrity of a file using sum, execute the following command:
sum -c checksum.txtHow to calculate the checksum of multiple files with sum?
To calculate the checksum of multiple files, use the following command:
sum file1.txt file2.txtCan 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:
sum -w file.txtHow 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:
sum -a SHA256 file.txtIs 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:
sum -t file.txtApplications of the sum command
- Checking for changes in files
- Verifying data integrity