Girish Mahajan (Editor)

Sha1sum

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

sha1sum is a computer program that calculates and verifies SHA-1 hashes. It is commonly used to verify the integrity of files. It (or a variant) is installed by default in most Unix-like operating systems. Variants include shasum (which permits SHA-1 through SHA-512 hash functions to be selected manually), sha224sum, sha256sum, sha384sum and sha512sum, which use a specific SHA-2 hash function, and sha3sum (which permits SHA-3 through SHA3-512, SHAKE, RawSHAKE and Keccak functions to be selected manually). Versions for Microsoft Windows also exist, and the ActivePerl distribution includes a perl implementation of shasum. On FreeBSD this utility is called sha512 and contains additional features.

Contents

The SHA-1 variants are proven vulnerable to collision attacks, and users should use for example a SHA-2 variant such as sha256sum instead to prevent tampering by an adversary.

It is included in GNU Core Utilities, Busybox and Toybox.

Usage

Several source code management systems, including Git, Mercurial, Monotone, and Fossil, use the sha1sum of various types of content (file content, directory trees, ancestry information, etc.) to uniquely identify them.

Examples

To create a file with an sha1 hash in it, if one is not provided:

If distributing one file, ".sha1" may be appended to the filename e.g.:

The output contains one line per file of the form "{hash} SPACE ASTERISK [{directory} SLASH] {filename}". For example:

To verify the file was downloaded correctly:

Hash file trees

sha1sum can only create checksums of one or multiple files inside a directory, but not of a directory tree, i.e. of subdirectories, sub-subdirectories, etc. and the files they contain. This is possible by using sha1sum in combination with the commands find and xargs (and optionally with sort so that the files are sorted in the checksum file).

References

Sha1sum Wikipedia