How to use the command sha384sum (with examples)
The sha384sum
command is used to calculate SHA384 cryptographic checksums for files. It can also be used to verify the integrity of files by comparing their checksums with previously calculated values.
Use case 1: Calculate the SHA384 checksum for one or more files
Code:
sha384sum path/to/file1 path/to/file2 ...
Motivation: This use case is useful when you want to calculate the SHA384 checksum for multiple files. It allows you to ensure the integrity of the files and detect any changes or corruption.
Explanation: The sha384sum
command is followed by the path to the file(s) for which you want to calculate the SHA384 checksum. You can specify one or more files, separated by spaces.
Example output:
e6a0fa4b2f96e201081018c8ef2a17ca24a038d30528f9f87ebfc7e2fcc39d41 file1
a6f36fe9db2902406060faf5d42b68c7af17f3c5f8e7212ee4c4efb8f611028a file2
Use case 2: Calculate and save the list of SHA384 checksums to a file
Code:
sha384sum path/to/file1 path/to/file2 ... > path/to/file.sha384
Motivation: Saving the list of SHA384 checksums to a file allows for easy comparison and verification of the files in the future. It provides a reference for the integrity of the files.
Explanation: The sha384sum
command is followed by the path to the file(s) for which you want to calculate the SHA384 checksum, just like in the previous use case. The output of the command is then directed to a file using the >
symbol, followed by the path to the output file.
Example output:
The SHA384 checksums of the files will be saved in the file.sha384
file.
Use case 3: Calculate a SHA384 checksum from stdin
Code:
command | sha384sum
Motivation: Sometimes you may have data coming from a command or from a pipeline, and you want to calculate the SHA384 checksum of that data. This use case provides a way to achieve that.
Explanation: In this use case, the sha384sum
command is used together with the pipe (|
) to receive data from a command or pipeline. The data is then processed by sha384sum
, which calculates the SHA384 checksum.
Example output:
c5c94ff066a233c1daa3802a05908514a3e2dbb461f786mddae4523b1e6250d2 -
In this example, the SHA384 checksum for the data received from the command is calculated, and the checksum is displayed along with a hyphen ("-"). The hyphen indicates that the input is from stdin
.
Use case 4: Read a file of SHA384 sums and filenames and verify all files have matching checksums
Code:
sha384sum --check path/to/file.sha384
Motivation: When you have previously calculated and saved the list of SHA384 checksums in a file, you can later use this file to check the integrity of the files. This use case helps to verify that the checksums of the files match the values in the file.
Explanation: The sha384sum
command is used with the --check
option followed by the path to the file containing the SHA384 sums and filenames. This option tells sha384sum
to verify the checksums of the files listed in the file.
Example output:
file1: OK
file2: OK
In this example, the sha384sum
command checks the checksums of the files listed in the file.sha384
file. If the checksums match the values in the file, it displays “OK” next to the filename. If there is a mismatch, it displays “FAILED” instead.
Use case 5: Only show a message for missing files or when verification fails
Code:
sha384sum --check --quiet path/to/file.sha384
Motivation: When verifying files using a list of SHA384 sums, it may be useful to only see a message when there are missing files or when the verification fails. This use case reduces the amount of output and focuses only on the necessary information.
Explanation: The sha384sum
command is used with the --check
option to verify the checksums of the files listed in the file. The --quiet
option is added to suppress the output for files that pass verification and only show messages for missing files or verification failures.
Example output:
If all files listed in the file.sha384
pass verification, there will be no output. If there are missing files or verification failures, a message will be displayed.
Use case 6: Only show a message when verification fails, ignoring missing files
Code:
sha384sum --ignore-missing --check --quiet path/to/file.sha384
Motivation: When verifying files, it may be beneficial to focus only on the verification failures and ignore missing files. This use case allows you to pinpoint any integrity issues with the files and take appropriate actions.
Explanation: The sha384sum
command is used with the --check
option to verify the files listed in the file. The --ignore-missing
option is added to ignore missing files and only show messages for verification failures. The --quiet
option is included to suppress unnecessary output.
Example output:
If all files listed in the file.sha384
pass verification or if there are missing files, there will be no output. Only when there are verification failures, a message will be displayed.