Using the sha224sum Command (with examples)
The sha224sum
command is a utility provided by the GNU Core Utilities that allows users to calculate SHA224 cryptographic checksums for one or more files. This checksum can be useful for verifying the integrity of files or ensuring that they have not been tampered with.
In this article, we will explore different use cases of the sha224sum
command and provide code examples to demonstrate each case. We will also discuss the motivations behind using each example, explain the arguments used in the command, and provide example outputs for better understanding.
1: Calculate the SHA224 checksum for one or more files
sha224sum path/to/file1 path/to/file2 ...
Motivation: This use case is handy when you want to calculate the SHA224 checksum for one or more specific files. It allows you to verify the integrity of the files and ensures that they have not been modified.
Explanation: The sha224sum
command followed by one or more file paths will calculate the SHA224 checksum for each file and display the checksum along with the file name.
Example Output:
7bd53a8aeed4a0a73c9c6047539830cde0ecaf9a1249bb1690c7054a path/to/file1
9b9385c2c8782b8c3804a96f58132c3145d7aba442955e1ba32a5d86 path/to/file2
2: Calculate and save the list of SHA224 checksums to a file
sha224sum path/to/file1 path/to/file2 ... > path/to/file.sha224
Motivation: This use case is useful when you need to calculate the SHA224 checksums for multiple files and save the results to a file. It allows you to reference the checksums later or share them with others for verification purposes.
Explanation: The sha224sum
command followed by one or more file paths and redirected >
to a file will calculate the SHA224 checksum for each file and save the list of checksums along with the respective file names to the specified file.
Example Output:
7bd53a8aeed4a0a73c9c6047539830cde0ecaf9a1249bb1690c7054a path/to/file1
9b9385c2c8782b8c3804a96f58132c3145d7aba442955e1ba32a5d86 path/to/file2
3: Calculate a SHA224 checksum from stdin
command | sha224sum
Motivation: This use case is helpful when you have data coming from a command or external source and want to calculate the SHA224 checksum for that data. It allows you to verify the integrity of the incoming data before further processing.
Explanation: The incoming data is piped to the sha224sum
command, which will calculate the SHA224 checksum for that data and display the checksum along with a dash -
sign.
Example Output:
e6e2e9e7d21113f4f0831b492861fee93db852439b3d3695e142a5fb -
4: Read a file of SHA224 sums and filenames and verify all files have matching checksums
sha224sum --check path/to/file.sha224
Motivation: This use case is useful when you have a file containing a list of SHA224 checksums and filenames, and you want to verify if the checksums match those calculated for each respective file. It allows you to ensure the integrity of the files and detect any modifications.
Explanation: The sha224sum
command with the --check
argument followed by a file containing the list of checksums and filenames will compare the stored checksums with the calculated checksums for each file and indicate if the checksums match or not.
Example Output:
path/to/file1: OK
path/to/file2: OK
5: Only show a message for missing files or when verification fails
sha224sum --check --quiet path/to/file.sha224
Motivation: This use case is beneficial when you want to verify the checksums for files but only receive a message when a file is missing or the verification fails. It helps to reduce unnecessary output and focus only on the files with issues.
Explanation: The sha224sum
command with the --check
and --quiet
arguments followed by a file containing the list of checksums and filenames will compare the stored checksums with the calculated checksums for each file. It will display a message only for files that are missing or fail the verification.
Example Output:
path/to/file2: FAILED
6: Only show a message when verification fails, ignoring missing files
sha224sum --ignore-missing --check --quiet path/to/file.sha224
Motivation: This use case is useful when you want to verify the checksums for files, but you are not concerned about missing files. It allows you to receive a message only when a verification fails, ignoring the missing files.
Explanation: The sha224sum
command with the --ignore-missing
, --check
, and --quiet
arguments followed by a file containing the list of checksums and filenames will compare the stored checksums with the calculated checksums for each file. It will display a message only when a verification fails, ignoring any missing files.
Example Output:
path/to/file2: FAILED
In conclusion, the sha224sum
command provides a convenient way to calculate SHA224 cryptographic checksums for files and verify their integrity. By using different arguments and redirecting output, users can efficiently calculate checksums, save them to files, verify checksums, and receive messages for failed verifications or missing files.