b2sum command is a utility to check the BLAKE2 checksum. BLAKE2 is a cryptographic hash function which is faster than MD5, SHA-1, SHA-2, and SHA-3 and is secure than the SHA-3. BLAKE2 has the features of high speed, security and simplicity. BLAKE2 is available in two flavors.
BLAKE2b (which is BLAKE2) – It is optimized for 64 bit platforms and produces digests of any size between 1 and 64 bytes
BLAKE2s – It is optimized for 8 to 32 bit platforms and produce digests of any size between 1 and 32 bytes
To implement BLAKE2 hash functions in Linux we use b2sum command.
b2sum command syntax:
b2sum [OPTION] [FILE]
Print the BLAKE2 checksum for standard input:
To generate the BLAKE2 checksum for user input or standard input use b2sum command with no options as below. After entering the b2sum command enter the user input in standard input and press Ctrl + D to exit from standard input. After this BLAKE2 check will be generated in the standard output.
$ b2sum
$ b2sum –
$ b2sum
Test line 1
Test line 2
Test line 3
f1ff67ee7ecb9f7c5265b291932af68d881405b773ffa4e176bf4316f8b51efb466ab3a3d61318788ee1231447a1980c295e62b38d1ad2487719df8666737bfc -
Read the file in binary mode to generate the checksum:
With -b or –binary option we can generate the BLAKE2 checksum by reading the file in binary mode instead of text mode. There is no difference between binary mode and text mode on GNU systems.
$ b2sum -b reports.txt
$ b2sum --binary reports.txt
$ b2sum -b reports.txt
1b14f0fbcd1b1cd761acc9a41565feef20b63c7fbd3f8b3810261610e2e7026f33883a784dff29b3233e78e2d255714d30250f7d1cd5f2a0c209981a73cea0f4 *reports.txt
Compare multiple checksums by reading from file:
If you want to compare the BLAKE2 checksum of multiple files mentioned in a file use -c or –check option with b2sum command.
If you want to learn about the Linux filesystem and the directory structure check this article
$ b2sum -c check_sum_data.txt
$ b2sum --check check_sum_data.txt
$ b2sum --check reports.txt
reports_1.txt: OK
reports_2.txt: OK
keyboards.txt: FAILED
countries.csv: OK
travel_list.txt: FAILED
Below is the sample file containing multiple checksums of respective file names mentioned in the file.
Check this detailed article about all cat command options with examples in Linux
$ cat reports.txt
b7082aee40a47f78dd21ee5637cew3h3 reports_1.txt
b7082aee40a47f78dd21ee563778f45rt reports_2.txt
f41e91a9d7b68f455f2b10cc36ee968e6 keyboards.txt
78dd21ee56377253b225221cf41e91a9d countries.csv
bf3a1ab2852e7fa369b055f77078f673e6 travel_list.txt
Generate checksum digest length in bits:
BLAKE2 checksum digest can be generated in custom lengths. Length should be multiple of 8. Minimum length of the digest is 0 and maximum is 512 bits. The values 0 and 512 are default. Without length if we generate the digest it will generate in default 512 bits length.
$ b2sum -l 8 reports.txt
$ b2sum --length 8 reports.txt
$ b2sum -l 16 reports.txt
$ b2sum -l 24 reports.txt
$ b2sum -l 32 reports.txt
$ b2sum -l 256 reports.txt
Generating checksum digest in 8 bits length:
$ b2sum -l 8 reports.txt
f0 reports.txt
Generating checksum digest in 64 bits length:
$ b2sum -l 64 reports.txt
2b504121de4db1ea reports.txt
Generating checksum digest in 256 bits length:
$ b2sum -l 256 reports.txt
246a637edd789ed40c20d574f6e93c238ecd8d89da4fb1033b3b6cf88950e2db reports.txt
Use tags while creating checksum digest:
To generate BSD-style checksum use tags option in b2sum command. With this option output is in BLAKE2 , filename , digest value format.
$ b2sum --tag reports.txt
BLAKE2b (reports.txt) = 1b14f0fbcd1b1cd761acc9a41565feef20b63c7fbd3f8b3810261610e2e7026f33883a784dff29b3233e78e2d255714d30250f7d1cd5f2a0c209981a73cea0f4
Generate checksum by reading the files in text mode:
To generate checksum we can mention the files reading mode. For reading in text mode use -t or –text. Text mode the default mode in b2sum command. To read files in binary mode use -b or –binary mode which is mentioned in above examples.
$ b2sum -t reports.txt
$ b2sum --text reports.txt
$ b2sum -t reports.txt
1b14f0fbcd1b1cd761acc9a41565feef20b63c7fbd3f8b3810261610e2e7026f33883a784dff29b3233e78e2d255714d30250f7d1cd5f2a0c209981a73cea0f4 reports.txt
Don’t print newline for the generated checksum:
By default generating checksum will add new line at the end of the digest created. If you don’t want to print the new line and use null at the end of the digest use -z or –zero option.
$ b2sum -z reports.txt
$ b2sum ---zero reports.txt
$ b2sum -z reports.txt
1b14f0fbcd1b1cd761acc9a41565feef20b63c7fbd3f8b3810261610e2e7026f33883a784dff29b3233e78e2d255714d30250f7d1cd5f2a0c209981a73cea0f4 reports.txt[test_user@localhost ~]$
Below options are useful when verifying the checksums
Don’t verify the missing files while checking from the list of files:
While reading the checksums from a file and comparing if any file is missed in that case it will report as failed. To ignore the missing files and don’t fail the status use –ignore-missing option with -c option in b2sum command.
$ b2sum --ignore-missing -c reports.txt
reports.txt: FAILED
b2sum: WARNING: 1 computed checksum did NOT match
b2sum: test.txt: no file was verified
Don’t print OK for successfully verified checksums:
For not printing the OK status of successfully verified files use –quiet option along with -c option in b2sum command.
$ b2sum --quiet -c reports.txt
Don’t print the output:
For not printing any output after checking the checksums use –status option.
$ b2sum --status -c reports.txt
Checking improperly formatted checksum lines:
While checking the checksums and if any of the checksums are improperly formatted for those exit with non-zero value.
$ b2sum --strict -c reports.txt
reports.txt: FAILED
b2sum: WARNING: 1 line is improperly formatted
b2sum: WARNING: 1 computed checksum did NOT match
Display warning message for improper checksums:
If any of the checksums mentioned in the file are improperly formatted with -w or –warn option warning message can be displayed for those checksums.
$ b2sum -w -c reports.txt
$ b2sum --warn -c reports.txt
$ b2sum -w -c reports.txt
reports.txt: FAILED
b2sum: reports.txt: 2: improperly formatted BLAKE2 checksum line
b2sum: WARNING: 1 line is improperly formatted
b2sum: WARNING: 1 computed checksum did NOT match
For more information on b2sum command please visit BLAKE2 site here.