csum Command
Purpose
The csum command calculates a message digest for the specified files using the specified hash algorithm.
Syntax
csum [-o outputfile] [-h algorithm] [-a] [File1, File2, ... | - ]
csum -i inputfile[-h algorithm]
Description
The csum command calculates a message digest for the specified files using the specified hash algorithm. This provides a reliable way to verify file integrity.
The csum command writes message digests to a specified file which can later be used to verify file integrity. Note that a file can be specified using absolute or relative path names.
Specifying multiple -i, -o or -h flags is not considered an error; the last instance of the flag specified will be used. However, it is an error to use both the -i and -o flags at the same time.
Flags
Item | Description |
---|---|
- | Specifies input from stdin. |
-a | Specifies that one message digest will be generated for all files. |
-h algorithm | Specifies which hash algorithms the csum command
will use to generate a message digest or verify the message digest
values when using the -i option. The following options are
available:
Note: these options are case sensitive.
If this -h option
is not used, then the csum command will default to using the
MD5 algorithm for both generating and verifying message digests. |
-i inputfile | Specifies an input file, generated by the -o flag,
which contains trusted message-digest values. The csum command
calculates the message-digest values of the files specified in the
input file and verifies that they match the actual message-digest
values of the existing file. The -h flag should be used with the -i flag to specify which cryptographic hash algorithm is used to generate the input file. If it is not specified, the MD5 algorithm will be used. If a file specified in the input file generates a message-digest value different than the value stored in the input file or the file does not exist, the test for that file will fail and the csum command will continue to process the files specified in the input file. |
-o outputfile | Specifies an output file that the csum command will use to write message-digest values. This flag cannot be used with the -i flag. If the file specified already exists, it will be overwritten. |
Exit Status
The command returns the following values:
Item | Description |
---|---|
0 | Success. |
>0 | An error occurred. |
Examples
- To calculate the message digest for the files
cars
andtrucks
, type:
Because the -h option is not specified, MD5 values are calculated for the filescsum cars trucks
cars
andtrucks
.If9875DD0B18C15899988F29E9D85346A4
andE8C3ABB5E1D48FA519135EAB0FE40932
are the MD5 values forcars
andtrucks
, respectively, the csum command outputs the following:9875DD0B18C15899988F29E9D85346A4 cars E8C3ABB5E1D48FA519135EAB0FE40932 trucks
- To calculate the message digest for all files with file names
beginning with file and store the output in a file called
mdvalues
, type:
The output file,csum -o mdvalues file*
mdvalues
, will contain the following text if the directory where the csum command is executed contains the filesfile1
,file2
, andfile3
and the MD5 values for those files are as listed below:B026324C6904B2A9CB4B88D6D61C81D1 file1 26AB0DB90D72E28AD0BA1E22EE510510 file2 D7FCE9FEE471194AA8B5B6E47267F03 file3
- To verify that the message digests in the file
mdvalues
match the current message-digest values for those same files, type:csum -i mdvalues
- To calculate the message digest for the file user.dat using
the SHA-1 algorithm, type:
If the SHA-1 value for the user.dat file iscsum -h SHA1 user.dat
A77CBB748AC336558AFA1AE7F2B73F3765728E7B
, the csum command will output the following:A77CBB748AC336558AFA1AE7F2B73F3765728E7B user.dat
Location
/usr/bin/csum