Wednesday, July 17, 2024
HomeHow toLinux cksum command explained for beginners (with examples)

Linux cksum command explained for beginners (with examples)

The cksum command in Linux is a utility that generates a CRC (Cyclic Redundancy Check) checksum and byte count for a given file. It is used to verify the integrity of files by comparing the checksum values before and after transmission or storage. The output of the cksum command consists of the CRC checksum, the number of bytes in the file, and the filename itself. This command is particularly useful in scripts and automated processes where file integrity needs to be ensured, as it provides a simple yet effective means of detecting accidental changes or corruption in files. By comparing the generated checksum of a file with a previously known value, users can confirm whether the file has remained unaltered.

There are times when we download a file (say an ISO image) hosted somewhere on the Internet only to find that it’s not working as expected (or at all). There could be multiple reasons behind this, one among them being file corruption (the file got corrupted during the download process, or the original, hosted file itself was corrupt). But how can we confirm that such corruption has occurred?

Well, there is a solution to this problem. In most cases, when a file is created, a checksum is computed that is unique to that file. Even if the file slightly changes, the checksum changes.

Most vendors offer a checksum (or a checksum-like code) corresponding to the file(s) being downloaded. If the file doesn’t behave as expected, users can recompute it and compare it with the original checksum provided by the vendor to see if the file is intact or corrupted.

In Linux, there’s a command-line tool called cksum that you can use to create/verify a checksum. In this tutorial, we will quickly discuss how the tool works.

Today, SHA1 or MD5 checksums are often used to verify files. See tutorials on the sha1sum command and md5sum command.

Linux cksum command

This command computes the input file’s Cyclic Redundancy Check (CRC) checksum and prints that number/code in its output on the command-line terminal. In addition to the checksum, the tool also shows the number of bytes the file contains.

Following is the generic syntax of the cksum command:

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

Here’s what the tool’s official documentation says about it:

`cksum' is typically used to ensure that files transferred by unreliable means (e.g., netnews) have not been corrupted, by comparing the `cksum' output for the received files with the `cksum' output for the original files (typically given in the distribution).

How to use cksum?

The usage of this tool is pretty simple: pass the file name as input, and the command will print the corresponding checksum as well as the number of bytes that are there in the file.

For example, we executed the following command in our case:

cksum file1

Here’s the above command in action:

So the first number in the output is the checksum, the second number is the number of bytes, and the third entity is the input file name.

Next, what we did was, we made a slight change in the file text and executed the same command again:

As you can see, the checksum changed, indicating that the file has changed.

That’s pretty much it about this tool. It offers a couple of options, but those are pretty generic (–help and –version) – they are self-explanatory and can also be found in almost every command’s option list in Linux.


The cksum command is simple to understand and even simpler to use. You can easily try it on your system – if there’s a file for which the corresponding CRC checksum is known, this tool can verify that the file is intact. For more information on cksum, head to the tool’s info page (run the command: info coreutils cksum), instead of its man page.



Please enter your comment!
Please enter your name here

Most Popular