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

    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 | diff - original.cksum
    # Process all text files in a directory find . -name "*.txt" -type f -exec cksum {} \;
    # Calculate checksums for all files in a tar archive tar -tvf archive.tar | awk '{print $6}' | xargs cksum # Combine with sha256sum for more secure verification cksum file.bin > file.checksums sha256sum file.bin >> file.checksums

    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.

    Related Commands

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

    Use Cases

    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