Cksum

Cksum


Linux cksum command

  • On Unix-like operating systems, the cksum command calculates a cyclic redundancy check (CRC) and byte count for each input file, and writes it to standard output.

  • This document covers the GNU/Linux version of cksum.

    Description

  • The checksum of a file is a simple way to check if its data has become corrupted when being transferred from one place to another. If the checksum value of the file is the same before and after being transferred, it is unlikely that any data corruption has accidentally occurred — from signal noise, for example.

  • Let's say you have a file, myfile.txt, containing the following text:

    This is my original file.
    You can calculate the checksum using cksum:

    cksum myfile.txt
    ...and this will be the output:

    4164605383 26 myfile.txt

  • Here, 4164605383 is the checksum, and 26 is the amount of data, in bytes. If you change the contents of the file to this:

  • This is no longer my original file.
    ...and run cksum again, you will see the following:

    cksum myfile.txt
    632554699 36 myfile.txt

  • The checksum is very different, and we can also see that there are ten more bytes of data.

  • The checksum will be different even if the number of bytes is same as the original:

    This is a corrupted file.
    cksum myfile.txt
    2256884274 26 myfile.txt
    ...and it will change dramatically even if only one character is different:

    This is my original file?
    cksum myfile.txt
    3832066352 26 myfile.txt

  • Important: Simple checksums, such as those produced by the cksum tool, are useful only for detecting accidental data corruption. It's not meant to protect against malicious alteration of a file. It's been proven that an attacker could carefully make changes to a file that would produce an identical cksum checksum. Therefore, if you need to be absolutely certain that a file is identical to the original, use a more powerful method. We highly recommend using the SHA256 algorithm for verifying data integrity. You can generate and verify SHA256 hash sums using tools such as GNU rhash.

    Syntax

  • The command syntax of the cksum command is very straightforward. Either specify one or more files to be checked:

    cksum FILE...
    ...or an option:

    cksum OPTION

  • If you run cksum with no file names and no options, it will create a checksum for data
    read from standard input.

    Options

    FILE

    The name of the file you want to check.

    --help

    Display a help message, and exit.

    --version

    Display version information, and exit.

    Examples

    cksum file.txt
    Calculate the checksum and bytecount of file.txt and output the values along with the file name. Output will be similar to the following:

    1740057581 19 file.txt
    Here, 1740057581 is the checksum, 19 is the number of bytes in the file, and file.txt is the file name.

    cksum myfile.txt myfile2.txt
    The above command will generate checksums and bytecounts for the files myfile.txt and myfile2.txt. Output will resemble the following:

    3832066352 26 myfile.txt
    3722946153 34 myfile2.txt
    cksum < myfile.txt
    The above command will redirect the contents of myfile.txt to cksum, which will read the data from standard input and output a checksum and bytecount.

    cat myfile.txt | cksum
    The above command will cat the contents of myfile.txt and pipe the output to cksum, which reads it from the standard input.

    cksum

  • Running cksum with no options will allow you to type anything you like, pressing enter for new lines. When you are finished entering text, you can press Ctrl-D to signal the end of standard input, and cksum will output the checksum and bytecount of the text that you entered.


    What is an Operating System? » Computer Shortcut Keys and their Functions » Keyboard Function Keys » Computer Basics - Hardware - Software - Parts

    Short Stories for Kids - Moral Stories – English Short Stories for Children - Moral Stories for Kids - Stories for Kids - Funny Story for Kids - Scary Stories for Kids - Really Funny Short Stories - Bedtime Stories
    Proverb Stories
    Powerful Motivational Quotes for Students » Success Quotes » English Short Stories for Kids

    Cabin Crew Jobs & Career Advice » Secretary Job Description » Receptionist Job Description » Top 100 Interview Questions and Answers » How to Prepare for an Interview » How to Write a CV » How to Choose a Career » Computer Shortcut Keys and their Functions

    Scholarships in Australia » Scholarships in Austria » Scholarships in Belgium » Scholarships in Canada » Scholarships in Germany » Scholarships in Ireland » Scholarships in Italy » Scholarships in Japan » Scholarships in Korea » Scholarships in Netherlands » Scholarships in Switzerland » Scholarships in UK » Scholarships in USA

    Scholarships for Study in Africa » Scholarships for African Students » Undergraduate Scholarships » African Women Scholarships & Grants Scholarships for Study in Africa » Scholarships for African Students » Undergraduate Scholarships » African Women Scholarships & Grants Scholarships for Study in Africa » Scholarships for African Students »

  • Click here to post comments

    Join in and write your own page! It's easy to do. How? Simply click here to return to Computer Basics FAQ.