How to use the command b3sum (with examples)

How to use the command b3sum (with examples)

b3sum is a command-line tool that is used to calculate BLAKE3 cryptographic checksums. These checksums can be used to verify the integrity of files and detect any changes or corruption. This article will illustrate each of the following use cases for the b3sum command.

Use case 1: Calculate the BLAKE3 checksum for one or more files

Code:

b3sum path/to/file1 path/to/file2 ...

Motivation: Calculating the BLAKE3 checksum for files is useful when you want to verify that the files have not been tampered with or corrupted. By comparing the calculated checksum with the expected checksum, you can ensure the integrity of your files.

Explanation: The b3sum command is followed by the paths to the files for which you want to calculate the checksum. You can provide multiple file paths separated by spaces.

Example output:

3c7b3d5db9e52b8f57ea4c4d4e6b5ac924e1e2ece272d4b63f86a3e0ccf642fb  path/to/file1
df1d866792d9754708c792f3333130918a4f0bf0ed48f82aef9a93306a747ae3  path/to/file2

Use case 2: Calculate and save the list of BLAKE3 checksums to a file

Code:

b3sum path/to/file1 path/to/file2 ... > path/to/file.b3

Motivation: Saving the list of BLAKE3 checksums to a file is useful when you want to store the checksums for future reference or to share them with others. This allows others to verify the integrity of the files using the saved checksums.

Explanation: In this use case, the output of the b3sum command is redirected to a file using the > operator. The path specified after the > operator indicates the file where the checksums will be saved.

Example output: The list of BLAKE3 checksums will be saved in the specified file, path/to/file.b3.

Use case 3: Calculate a BLAKE3 checksum from stdin

Code:

command | b3sum

Motivation: Calculating a BLAKE3 checksum from stdin is useful when you want to calculate the checksum of data that is being piped from another command. This allows you to calculate the checksum without having to save the data to a file first.

Explanation: In this use case, the output of the command preceding the | operator is piped as the input to the b3sum command. This allows the b3sum command to calculate the checksum based on the input received from the previous command.

Example output:

e4ffead7e46c2e644af5c5b3267ddfaee1474cdab1a0bd6222a4783b68b59a32  (stdin)

Use case 4: Read a file of BLAKE3 sums and filenames and verify all files have matching checksums

Code:

b3sum --check path/to/file.b3

Motivation: Verifying the checksums of multiple files against a file containing the expected checksums is useful when you want to ensure that the files have not been modified or corrupted. This can be especially useful when verifying a large number of files.

Explanation: The --check option is used to indicate that the command should verify the checksums instead of calculating them. The path specified after the --check option is the file that contains the expected checksums and corresponding filenames.

Example output:

path/to/file1: OK
path/to/file2: OK

Use case 5: Only show a message for missing files or when verification fails

Code:

b3sum --check --quiet path/to/file.b3

Motivation: When verifying the checksums of multiple files, it may be desirable to only receive a message for missing or failed verifications. This can help reduce the amount of output and make it easier to identify files that require attention.

Explanation: The --quiet option is used to suppress the output for files that have matching checksums. Only messages for missing files or verification failures will be displayed.

Example output:

path/to/missing_file: Failed

Conclusion:

The b3sum command is a versatile tool for calculating and verifying BLAKE3 cryptographic checksums. It can be used to ensure the integrity of files and detect any changes or corruption. By using these examples, you can effectively use the b3sum command in your workflows.

Related Posts

How to use the command base32 (with examples)

How to use the command base32 (with examples)

The base32 command is a command-line tool that can be used to encode or decode files or standard input to/from Base32 format.

Read More
How to Use the Command "git effort" (with examples)

How to Use the Command "git effort" (with examples)

Git is a popular distributed version control system that allows developers to track changes in their codebase.

Read More