LinuxCommandLibrary

shasum

Verify file integrity using SHA checksums

TLDR

Calculate the SHA1 checksum for one or more files

$ shasum [path/to/file1 path/to/file2 ...]
copy

Calculate the SHA checksum for one or more files with the specified algorithm
$ shasum --algorithm [1|224|256|384|512|512224|512256] [path/to/file1 path/to/file2 ...]
copy

Calculate a SHA1 checksum from stdin
$ [command] | shasum
copy

Calculate and save the list of SHA256 checksums to a file
$ shasum --algorithm 256 [path/to/file1 path/to/file2 ...] > [path/to/file.sha256]
copy

Read a file of SHA checksums and filenames and verify all files have matching checksums (the algorithm will be automatically detected)
$ shasum [[-c|--check]] [path/to/file]
copy

Only show a message for missing files or when verification fails
$ shasum [[-c|--check]] --quiet [path/to/file]
copy

Only show a message when verification fails, ignoring missing files
$ shasum --ignore-missing [[-c|--check]] --quiet [path/to/file]
copy

Check a known SHA checksum of a file
$ echo [known_sha_checksum_of_the_file] [path/to/file] | shasum [[-c|--check]]
copy

SYNOPSIS

shasum [OPTION]... [FILE]...
shasum -c [OPTION]... [FILE]...

PARAMETERS

-a algorithm, --algorithm=algorithm
    Selects the SHA algorithm (1, 224, 256, 384, 512). Default is SHA-1.

-b, --binary
    Reads files in binary mode (default on most systems).

-c, --check
    Reads SHA sums from files and verifies them.

-p, --portable
    Produces checksums in a portable format.

-t, --text
    Reads files in text mode.

-U, --universal
    Produces checksums in a universal format.

-0, --zero
    Ends each output line with a null character (for use with xargs -0).

--ignore-missing
    When checking, do not report or fail for missing files.

--quiet
    When checking, suppress 'OK' messages for verified files.

--status
    Suppress all output, only return exit status.

--strict
    When checking, exit non-zero for improperly formatted lines.

--warn
    When checking, warn about improperly formatted lines.

--version
    Displays version information and exits.

--help
    Displays help message and exits.

DESCRIPTION

shasum is a command-line utility used to compute and verify SHA hash values (SHA-1, SHA-224, SHA-256, SHA-384, SHA-512) for files or standard input. It's crucial for ensuring data integrity and authenticity. When you download a file, its publisher often provides a checksum. You can then run shasum on the downloaded file and compare the calculated checksum with the provided one. If they match, it confirms that the file has not been altered or corrupted during transmission. shasum supports various SHA algorithms, making it versatile for different security requirements. It can also read checksums from a file (generated by a previous shasum run) and verify them against the actual files, reporting any mismatches. This feature is particularly useful for batch verification of multiple files.

CAVEATS

shasum is typically part of Perl's Digest::SHA module and might not be pre-installed on all minimal Linux distributions. It generally provides more SHA algorithm options than older utilities like sha1sum, sha256sum, etc., which are often from GNU Coreutils.

EXIT STATUS

shasum exits with 0 if all checks passed or if no files were specified and successfully processed. A non-zero exit status indicates an error (e.g., checksum mismatch, file not found, invalid argument).

USAGE EXAMPLES

Calculating a SHA-256 sum for a file:
`shasum -a 256 my_file.txt`

Verifying checksums from a file:
`shasum -c checksums.sha`

Calculating sum from standard input:
`echo "hello world" | shasum`

Generating a checksum file for multiple files (SHA-512):
`shasum -a 512 *.zip > all_zips.sha512`

Checking the generated file:
`shasum -c all_zips.sha512`

HISTORY

shasum emerged as a versatile utility from the Digest::SHA Perl module, primarily developed and maintained by individuals like Mark Shelor. Its ability to handle various SHA algorithms via a single command, configurable with the -a flag, made it a popular choice, particularly in environments leveraging Perl. It often serves as a flexible alternative or complement to the more specific *sum utilities found in GNU Coreutils.

SEE ALSO

md5sum(1), sha1sum(1), sha256sum(1), sha512sum(1), cksum(1), sum(1)

Copied to clipboard