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.
sum --help
Version
TO check sum installed version, use command sum –version.
sum --version
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
sum filename
sum a.txt
Here 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
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.
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.
sum -r filename
sum -r a.txt
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 command can be used to verify copied file
—
—