cksum

file managementLinux/Unix
The cksum command is one of the most frequently used commands in Linux/Unix-like operating systems. cksum Calculate CRC checksum and byte count for a file

Quick Reference

Command Name:

cksum

Category:

file management

Platform:

Linux/Unix

Basic Usage:

cksum [options] [arguments]

Common Use Cases

  • 1

    Data integrity verification

    Verify file integrity using checksums

  • 2

    File corruption detection

    Detect corrupted files by comparing checksums

  • 3

    Data transfer validation

    Verify successful data transfers between systems

  • 4

    Backup verification

    Ensure backup files are not corrupted

Syntax

cksum [OPTION]... [FILE]...

Options

Option Description
--help Display help message and exit
--version Output version information and exit

Note: The cksum command has few options as it's designed to be a simple, standard utility. For more advanced checksum calculations, consider using md5sum, sha1sum, or sha256sum.

Examples

How to Use These Examples

The examples below show common ways to use the cksum command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

Basic Examples:

Calculate checksum for a single file
cksum filename.txt
Calculate checksums for multiple files
cksum file1.txt file2.txt file3.txt
Calculate checksum for data from stdin
echo "Hello World" | cksum
Calculate checksum and redirect output to a file
cksum important_data.bin > important_data.cksum

Advanced Examples:

Verify file integrity by comparing checksums
cksum original.iso > original.cksum
cksum downloaded.iso > downloaded.cksum diff original.cksum downloaded.cksum
Process all text files in a directory
find /path/to/directory -name "*.txt" -exec cksum {} \;
Calculate checksums for all files in a tar archive
tar -tf archive.tar | xargs cksum
Combine with sha256sum for more secure verification
cksum file.bin > file.checksums
sha256sum file.bin >> file.checksums
Check if a file has been modified by comparing checksums
cksum config.conf > config.conf.original
Later, to check if modified:
cksum config.conf | diff - config.conf.original

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

The cksum command calculates a cyclic redundancy check (CRC) value and the byte count for one or more files. It's commonly used to verify file integrity, especially when transferring files between systems.

Key points about cksum:

  • It uses a 32-bit CRC algorithm based on the Ethernet standard
  • The output format is: CRC value, byte count, and filename
  • If no file is specified or if file is -, cksum reads from standard input
  • The command is part of the POSIX standard, making it available on most Unix-like systems
  • For security-critical applications, cksum is not considered cryptographically secure - use sha256sum or similar instead

When verifying file integrity:

  1. Calculate the checksum of the original file
  2. Transfer both the file and its checksum
  3. Calculate the checksum on the received file
  4. Compare the two checksums - they should match if the file is intact

The cksum command is especially useful for quick verification of file integrity during transfers, backups, or when checking if files have been modified.

Common Use Cases

Data integrity verification

Verify file integrity using checksums

File corruption detection

Detect corrupted files by comparing checksums

Data transfer validation

Verify successful data transfers between systems

Backup verification

Ensure backup files are not corrupted

Quality assurance

Validate file integrity in automated workflows

Related Commands

These commands are frequently used alongside cksum or serve similar purposes:

Use Cases

1

Data integrity verification

Verify file integrity using checksums

2

File corruption detection

Detect corrupted files by comparing checksums

3

Data transfer validation

Verify successful data transfers between systems

4

Backup verification

Ensure backup files are not corrupted

5

Quality assurance

Validate file integrity in automated workflows

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the cksum command works in different scenarios.

$ cksum
View All Commands