![]() |
![]() | This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages) (Learn how and when to remove this message)
|
sha1sum is acomputer program that calculates and verifiesSHA-1hashes. It is commonly used to verify the integrity of files. It (or a variant) is installed by default on mostLinux distributions. Typically distributed alongsidesha1sum
aresha224sum,sha256sum,sha384sum andsha512sum, which use a specificSHA-2 hash function andb2sum,[1] which uses theBLAKE2 cryptographic hash function.
The SHA-1 variants areproven vulnerable tocollision attacks, and users should instead use, for example, a SHA-2 variant such assha256sum or theBLAKE2 variantb2sum to prevent tampering by an adversary.[2][3]
It is included inGNU Core Utilities,[4]Busybox (excludingb2sum),[5] andToybox (excludingb2sum).[6] Ports to a wide variety of systems are available, includingMicrosoft Windows.
To create a file with a SHA-1 hash in it, if one is not provided:
$sha1sumfilename[filename2]...>SHA1SUM
If distributing one file, the.sha1file extension may be appended to the filename e.g.:
$sha1sum--binarymy-zip.tar.gz>my-zip.tar.gz.sha1
The output contains one line per file of the form "{hash} SPACE (ASTERISK|SPACE) [{directory} SLASH] {filename}
". (Note well, if the hash digest creation is performed in text mode instead of binary mode, then there will be two space characters instead of a single space character and an asterisk.) For example:
$sha1sum-bmy-zip.tar.gzd5db29cd03a2ed055086cef9c31c252b4587d6d0 *my-zip.tar.gz$sha1sum-bsubdir/filename255086cef9c87d6d031cd5db29cd03a2ed0252b45 *subdir/filename2
To verify that a file was downloaded correctly or that it has not been tampered with:
$sha1sum-cSHA1SUMfilename: OKfilename2: OK$sha1sum-cmy-zip.tar.gz.sha1my-zip.tar.gz: OK
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 usingsha1sum in combination with thefind
command with the-exec
option, or bypiping the output fromfind intoxargs
.sha1deep can create checksums of a directory tree.
To usesha1sum withfind:
$finds_*-typef-execsha1sum'{}'\;65c23f142ff6bcfdddeccebc0e5e63c41c9c1721 s_1/file_s11d3d59905cf5fc930cd4bf5b709d5ffdbaa9443b2 s_2/file_s215590e00ea904568199b86aee4b770fb1b5645ab8 s_a/file_02
Likewise, piping the output fromfind intoxargs yields the same output:
$finds_*-typef|xargssha1sum65c23f142ff6bcfdddeccebc0e5e63c41c9c1721 s_1/file_s11d3d59905cf5fc930cd4bf5b709d5ffdbaa9443b2 s_2/file_s215590e00ea904568199b86aee4b770fb1b5645ab8 s_a/file_02
b2sum
andb3sum
, by the programtthsum
, and many others.shasum(1)
– Linux General CommandsManualsha3sum(1)
– Linux General CommandsManualmd5(1)
– FreeBSD General CommandsManual