sum command in Linux, Uses of sum command with examples

sum command in Linux gives us information about file checksum and the number of blocks in a file. The sum command is often used to find out whether a file has been copied.

  • It is one of the oldest checksum commands, dating back to the first version of Unix, from 1971.
  • sum command displays the block count and checksum for each specified file.
  • When no file is specified then it will read the standard input.
  • If no options are specified, a byte-by-byte algorithm is used.

Syntax for sum command

sum [OPTION]...[file1] [file2]....

How to use sum command

To know how to use sum command and get help for sum command and find options available with sum command, Use sum –help command.

Load WordPress Sites in as fast as 37ms!
 sum --help

sum --help command in Linux

Version

TO check sum installed version, use command sum –version.

sum --version

sum --version command in Linux

Load WordPress Sites in as fast as 37ms!

Using sum command with examples

sum command can be used with single file or multiple files. Simply using sum command with any file and without any option will display file checksum and the number of 1024-byte blocks in that file.

For single file

Load WordPress Sites in as fast as 37ms!
sum filename
sum a.txt

sum filename command in LinuxHere sum command is used with filename “a.txt”, checksum of the file “a.txt” is 30177 and this file containing four blocks.

For multiple files

sum file1 file2
sum a.txt b.txt

sum file1 file2 command in Linux

Here sum command is used with filename “a.txt, b.txt”. Checksum of the file named “a.txt” is 30177 and this file containing four blocks and checksum of the file named “b.txt” is 13054 and this file is also containing four blocks.

Load WordPress Sites in as fast as 37ms!

Using sum command with -r option

sum command with -r option display file checksum and the number of 1K blocks in that file.

** 1K is equivalent to 1024 bytes. Since, using sum command without any option display the checksum and number of 1024-byte blocks in that file. So, you may notice the output of sum command with -r option and without any option is same.

Load WordPress Sites in as fast as 37ms!
sum -r filename
sum -r a.txt

sum -r filename command in Linux

Using sum command with -s option

sum command with -s option display file checksum and the number of 512 bytes blocks in that file.

Since, sum command without any option display number of 1024-byte blocks in that file. So, you may notice the number of blocks with -s option is double the number of blocks without any option.

sum -s filename
sum -s a.txt

sum -s filename command in Linux

Load WordPress Sites in as fast as 37ms!

sum command can be used to verify copied file

sum command can be used to verify copied file

sum command can be used to verify copied file

 

Sharing is Caring
Load WordPress Sites in as fast as 37ms!
Scroll to Top