The csum command calculates a message digest for the specified files using the specified hash algorithm.
csum [-o outputfile] [-h algorithm] [-a] [File1, File2, ... | - ]
csum -i inputfile[-h algorithm]
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.
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. |
The command returns the following values:
Item | Description |
---|---|
0 | Success. |
>0 | An error occurred. |
csum cars trucks
Because the -h option
is not specified, MD5 values are calculated for the files cars and trucks. 9875DD0B18C15899988F29E9D85346A4 cars
E8C3ABB5E1D48FA519135EAB0FE40932 trucks
csum -o mdvalues file*
The output file, mdvalues,
will contain the following text if the directory where the csum command
is executed contains the files file1, file2,
and file3 and the MD5 values for those files are
as listed below: B026324C6904B2A9CB4B88D6D61C81D1 file1
26AB0DB90D72E28AD0BA1E22EE510510 file2
D7FCE9FEE471194AA8B5B6E47267F03 file3
csum -i mdvalues
csum -h SHA1 user.dat
If
the SHA-1 value for the user.dat file is A77CBB748AC336558AFA1AE7F2B73F3765728E7B,
the csum command will output the following: A77CBB748AC336558AFA1AE7F2B73F3765728E7B user.dat
/usr/bin/csum