Shasum Cheat Sheet
Table of contents
Command Cheat Sheet
The shasum command is used to calculate and verify SHA (Secure Hash Algorithm) checksums of files. It computes the hash values of files using different SHA algorithms such as SHA-1, SHA-224, SHA-256, SHA-384, or SHA-512.
Basic Usage:
shasum [OPTIONS] [FILES]
Options:
-a,--algorithm <algorithm>: Specifies the SHA algorithm to use. Supported options are1,224,256,384, and512. The default is SHA-256.-c,--check: Reads checksums from a file and verifies them against the given files.-b,--binary: Reads files in binary mode (useful for non-text files).-p,--portable: Produces output in a portable format that can be used across different platforms.-s,--status: Suppresses normal output and only displays the status of checksum verification.-t,--text: Reads files in text mode (default behavior).-v,--verbose: Enables verbose output, showing filenames and status for each file processed.--version: Displays the version information forshasum.--help: Displays the help message forshasum.
Examples:
Calculating SHA (Secure Hash Algorithm):
- Calculate SHA-256 Hash:
shasum -a 256 filename - Calculate SHA-512 Hash (Verbose Output):
shasum -a 512 -v filename - Calculate SHA-256 Hash for Multiple Files:
shasum -a 256 file1.txt file2.txt - Calculate SHA-256 Hash in Binary Mode:
shasum -a 256 -b filename - Calculate SHA-256 Hash in Portable Mode:
shasum -a 256 -p filename
Verifying and checking SHA (Secure Hash Algorithm):
- Check Single File Integrity:
shasum --check checksums.txtshasum -a 256 -c checksums.txtshasum -a 256 -c checksums.txt --ignore-missingshasum -a 512 -c checksums.txt --ignore-missing- These commands read the checksums from the
checksums.txtfile and verifies the integrity of the files listed.
- These commands read the checksums from the
- Check Multiple File Integrity:
shasum -a 512 -c *.sha512- This command reads the checksums from all
.sha512files in the current directory and verifies the integrity of the corresponding files using SHA-512 hash algorithm.
- This command reads the checksums from all
- Check Integrity with Verbose Output:
shasum -a 256 -c -v checksums.txt- The
-voption provides verbose output, displaying the filename along with the result of the integrity check for each file.
- The
- Check Integrity of Binary Files:
shasum -a 256 -c -b checksums.bin- Use the
-boption to read binary files and verify their integrity against the checksums provided inchecksums.bin.
- Use the
- Check Integrity of a Single File:
shasum -a 1 -c file1.txt.sha1- This command verifies the integrity of
file1.txtusing the SHA-1 hash algorithm and the checksum provided infile1.txt.sha1.
- This command verifies the integrity of
- Check Integrity and Suppress Output:
shasum -a 256 -s -c checksums.txt- The
-soption suppresses normal output, useful for scripting. It only shows a summary of the integrity check status.
- The
- Check Integrity of Files Listed in a Directory:
shasum -a 256 -c /path/to/directory/checksums.txt- This command reads the checksums from
checksums.txtlocated in the specified directory and verifies the integrity of the files listed within it using SHA-256 hash algorithm.
- This command reads the checksums from
- Check Integrity Using Portable Mode:
shasum -a 256 -c -p checksums.txt- The
-poption produces a portable result, which can be useful when comparing checksums across different platforms or systems.
- The
Output Format:
The default output format of shasum is:
<checksum> <filename>
<checksum>: The computed hash value of the file.<filename>: The name of the file.
If the -p (portable) option is used, the output format changes to:
<checksum> *<filename>
<checksum>: The computed hash value of the file.<filename>: The name of the file, preceded by an asterisk.
Security Considerations:
- Checksums are used to verify the integrity of files and detect any changes. They do not provide encryption or protection against malicious modifications.
- Always obtain checksum values from trusted sources to ensure their authenticity.
- Use a secure channel to transfer or share checksum values to prevent tampering.
- Verify checksums using a trusted tool and compare against multiple sources if possible.
Remember to consult the shasum command’s documentation or man page for further information or specific details related to your system.