cksum computes and verifies 32-bit CRC checksums using the IEEE 802.3 CRC algorithm, outputting the CRC digest, byte count, and filename.
cksum document.pdf
Tested on Ubuntu 22.04 with Linux 5.15.x; verify against vendor docs for non-Debian distributions or older kernels.
Syntax
cksum [OPTION]... [FILE]...
When no FILE or FILE is -, read standard input. By default uses the 32-bit CRC algorithm (cksum).
Options and Flags
| Flag | Type | Default | Description |
|---|---|---|---|
-a, --algorithm=TYPE |
string | cksum | Select digest type. Supported: cksum, md5, rmd160, sha1, sha224, sha256, sha384, sha512, sha512/256. |
--base64 |
flag | hex | Emit base64-encoded digests instead of hexadecimal. |
-c, --check |
flag | N/A | Read checksum files and verify integrity. |
--debug |
flag | N/A | Print internal debug information. |
--help |
flag | N/A | Display help and exit. |
--ignore-missing |
flag | N/A | Skip missing files in check mode without error. |
-l, --length=BITS |
integer | 32 | Digest length in bits (for algorithms that support variable length). |
--quiet |
flag | N/A | Suppress OK/FAIL messages in check mode; only output errors. |
--raw |
flag | N/A | Emit raw binary digest, no filename or newline. |
-s, --status |
flag | N/A | Exit code only; no output. Useful for scripts. |
--strict |
flag | N/A | Treat malformed checksum lines as errors. |
-t, --tag |
flag | N/A | Output in BSD-style tagged format (algorithm:digest). |
--untagged |
flag | N/A | Suppress algorithm prefix in output. |
--version |
flag | N/A | Display version information and exit. |
--warn |
flag | N/A | Warn about malformed checksum lines (default). |
-z, --zero |
flag | N/A | Use NUL instead of newline as line terminator. |
Usage Examples
1. Check CRC of a Single File
cksum document.pdf
Outputs the 32-bit CRC checksum, byte count, and filename. Use this after a file transfer to verify the file arrived intact.
2. Check CRC of Multiple Files
cksum file1.txt file2.txt file3.txt
Each file gets its own line. Ideal for batch verification of archival sets or backup directories.
3. Calculate CRC Using Standard Input
echo "Hello Linux" | cksum
Reads from piped data. Useful for verifying dynamically generated content or network streams.
4. Save Checksum Output to a File
cksum file.txt > file_checksum.txt
Redirects output to a checksum file. This file can later be used with --check to verify integrity.
5. Compare Current CRC with Stored CRC
cksum file.txt | diff - file_checksum.txt
If diff produces no output, the checksums match. A simple integrity check without --check.
6. Verify Using --check Mode
cksum --check file_checksum.txt
Reads the saved checksum file and verifies each listed file. Reports “OK” or “FAILED” per file.
7. Use SHA-256 Instead of CRC
cksum -a sha256 important.iso
Convenient when your workflow requires a stronger hash. No need to call sha256sum separately.
Troubleshooting & Common Errors
| Error Message / Code | Root Cause | Resolution Command |
|---|---|---|
cksum: file.txt: No such file or directory |
Path missing or typo. | ls -l /path/to/file.txt then correct the path. |
cksum: file.txt: Permission denied |
Insufficient read rights. | chmod +r file.txt or run under appropriate user. |
Exit code 1 when using --check |
Stored CRC or byte count does not match current file. | Re-generate checksum after re-transfer: cksum file.txt > new_checksum.txt; compare with original. |
cksum: invalid algorithm: md5 (old version) |
GNU coreutils older than 9.0 does not support -a. |
Upgrade coreutils or use md5sum directly. |
Multi-Cloud Comparison
cksum is a local Unix utility; no direct cloud CLI subcommand provides the same CRC-32 algorithm. Cloud object stores offer built-in checksum verification (e.g., AWS S3 uses CRC32 for PutObject; Azure Blob Storage uses MD5 or CRC64). When transferring files to the cloud, generate a local CRC with cksum and compare with the cloud-reported checksum using scripting.
Exit Codes
| Code | Meaning | Operational Impact |
|---|---|---|
| 0 | All files processed successfully (or all checksums verified OK). | Normal operation; continue pipeline. |
| 1 | One or more files failed verification (in --check mode) or could not be read. |
Trigger alert or re-transfer. |
| 2 | Invalid command-line option or argument. | Check syntax and re-run. |
| 3+ | Internal error or system call failure. | Inspect system logs and file permissions. |
Closing Tip
For automated cron-based integrity checks, use cksum --check --status to suppress output and rely solely on exit codes, piping action into a monitoring system.
Performance Considerations
cksum is typically I/O-bound on large files; performance tuning focuses on reducing process overhead and exploiting parallelism. The following techniques are based on system-level knobs and GNU coreutils behavior.
- Algorithm choice: The default CRC32 is fast;
cksum -a sha256 bigfileincreases CPU overhead. See thecksum(1)man page for supported algorithms. - Batch processing: Passing multiple files in one command reduces fork/exec overhead. Example:
cksum file1 file2 file3. - Parallelism: On multi-core systems, use
findwithxargs -Pto run concurrent instances:find . -type f -print0 | xargs -0 -n 1 -P 4 cksum. - Verification mode: Use
--checkwith a pre-computed checksum file to avoid redundant I/O per file.
# Measure default CRC32 performance on a large file
time cksum /path/to/largefile.bin
# Parallel check of all .iso files using 4 cores
find /mnt -name '*.iso' -print0 | xargs -0 -n 1 -P 4 cksum -a sha256
Real-world tuning requires matching these knobs to your hardware. The GNU coreutils documentation provides further details.
Frequently Asked Questions
What is the difference between cksum -a md5 and md5sum on Linux?
Answer: Both compute MD5 hashes, but cksum -a md5 outputs format “hash bytes filename”, while md5sum uses “hash filename”.
The cksum command (GNU coreutils) with -a md5 uses the same algorithm as md5sum but diverges in output format and exit behavior. cksum omits the double space in output and lacks the --check mode for verifying hash files. For strict POSIX CRC-32, always use cksum without flags.
# Compare output formats
echo "test" > /tmp/example.txt
cksum -a md5 /tmp/example.txt # Output: /tmp/example.txt
md5sum /tmp/example.txt # Output: /tmp/example.txt
Does cksum work on macOS and FreeBSD for cross-platform CRC verification?
Answer: Yes, but macOS and BSD use a different CRC-32 algorithm producing different checksums than GNU/Linux for the same file.
POSIX cksum is present on all three platforms, but the CRC-32 implementation diverges: GNU coreutils uses reversed polynomial representation. BSD/macOS output is only compatible with other BSD systems. For portable verification across Linux and macOS, use sha256sum or md5sum instead of cksum.
# Verify checksum consistency across platforms
# GNU/Linux (coreutils) output
cksum /tmp/file.txt
# macOS (BSD) output will differ for the same file
What is the fastest way to checksum 100,000 files with cksum and store results?
Answer: Use find -print0 | xargs -0 -P $(nproc) cksum to parallelize across all CPU cores and reduce total runtime by 10-20x.
The single-threaded approach (find ... -exec cksum {} +) is I/O bound. Adding -P with xargs spawns concurrent processes, saturating disk read throughput. Always use -print0 and -0 to handle special characters safely. Redirect output to a file for later verification.
# Parallel checksum of 100K files using all cores
find /data -type f -print0 | xargs -0 -P "$(nproc)" cksum > /tmp/master_checksum.list

Command Line Expert & Software Engineer
Welcome! I’m Thomas Heinrich, a software engineer and system administrator with a deep passion for the Command Line Interface (CLI). With years of experience navigating the terminal, building backend architectures, and automating server deployments, I created this space to share practical, real-world terminal knowledge.
Whether you are a beginner taking your first steps in a Linux environment or a seasoned DevOps engineer looking to optimize your deployment scripts, you will find actionable solutions here. My goal is to help you ditch the mouse, speed up your workflow, and harness the full power of the command line.