rhash

When you need to verify that files haven't been corrupted, tampered with, or accidentally modified, hashing tools are invaluable. rhash is a versatile command-line utility that calculates cryptographic digests—everything from simple CRC32 checksums to advanced SHA3 hashes. Whether you're checking downloaded files or maintaining archives, here's how to make rhash work for you.

Understanding rhash: What It Does

rhash generates cryptographic hashes that uniquely identify file contents. If even a single byte changes, the hash changes entirely, making it perfect for detecting corruption or tampering. Unlike some specialized tools, rhash supports multiple hashing algorithms in one package, so you can use whatever digest method fits your needs.

The Basics: Quick Hash Calculations

Generate a Default Checksum

The simplest use case is calculating a CRC32 digest (the default algorithm):

rhash {{path/to/file}}

This shows you a quick hash of the file. CRC32 is fast and good for detecting accidental corruption, though it's not cryptographically secure.

Calculate SHA3-256 of Text

Need to hash a message rather than a file? rhash can work with plain text:

rhash --sha3-256 --message '{{message}}'

This is useful when you need to verify a specific text snippet or create a digest without writing to disk first.

Creating Checksums for Entire Directories

Generate an SFV File Recursively

SFV (Simple File Verification) files are lists of hashes for multiple files, making them perfect for archiving or distributing. To recursively hash all files in a directory using SHA1 and save to an SFV file:

Recursively process a directory to generate an SFV file using SHA1:

rhash --sha1 --recursive {{path/to/folder}} > {{path/to/output.sfv}}

This walks through all subdirectories, hashes each file, and saves the checksums in a standard format.

Quick SFV from Current Directory

Working in the directory you want to hash? Create checksums right there:

rhash --sha1 --recursive . > checksums.sfv

The dot (.) refers to the current folder, so this is a convenient one-liner for archival work.

Verifying File Integrity

Once you've created checksums, verification is just as easy:

rhash --check {{path/to/file.sfv}}

This reads the SFV file and compares each file's current hash against the stored digest. If everything matches, you're good. If something changed, rhash alerts you immediately.

Advanced Hashing: Algorithm Selection and Formatting

Output in Base64 with BSD Format

By default, rhash outputs hashes in hexadecimal. But if you need base64 encoding in BSD format (common in some security tools and cryptographic applications):

rhash --base64 --bsd {{path/to/file}}

This encodes the digest in a compact base64 representation, useful for specific workflows or compatibility requirements.

Custom Output Templates

rhash's real power lies in its template system, letting you customize exactly what gets displayed. Here's an example that shows filepath, file size, modification time, and hash:

rhash --printf '{{%p\t%s\t%{mtime}\t%m\n}}' {{path/to/file}}

Template variables include:

This flexibility means you can create custom reports tailored to your workflow.

Common Use Cases and Examples

Use Case Command Why
Quick hash verification rhash file.zip Fast CRC32 check for accidental corruption
Archive backup checksums rhash --sha1 --recursive ./project > backup.sfv Create permanent record of files before major changes
Verify download integrity rhash --check download.sfv Ensure files weren't corrupted during transfer
Cryptographic digest rhash --sha3-256 file.bin Strong hash for security-sensitive verification
Custom report output rhash --printf '%p: %m\n' *.jpg Generate clean reports for auditing

rhash vs. Other Hashing Tools

You might wonder when to use rhash versus xxhsum or sha256sum. Here's the breakdown:

If you're managing complex archival projects with varied requirements, rhash is your best friend. If you're optimizing for raw speed on massive datasets, xxhsum wins.

Putting It Together: A Real-World Workflow

Let's say you're archiving a project with custom reporting requirements:

Create detailed checksums with custom formatting.

rhash --sha1 --printf '%p\t%m\n' --recursive . > archive-manifest.txt

Later, verify everything is intact rhash --check archive-manifest.txt.

Or if you're distributing files and want recipients to verify downloads:

Create an SFV file to distribute with your files.

rhash --sha1 --recursive ./release > CHECKSUMS.sfv

Recipients can verify with: rhash --check CHECKSUMS.sfv.

Note

rhash is the Swiss Army knife of file hashing. Whether you're a system administrator managing archives, a developer verifying downloads, or someone who just wants peace of mind about file integrity, rhash gives you power, flexibility, and multiple algorithms in a single command-line tool. Learning its basics takes minutes, but the reliability it provides is invaluable.