cksum command in Linux with examples

Transferring files is a common activity you’ll frequently engage in, whether you are using Linux or any other operating system. Typically, this will go pretty smoothly, as this process is not very complex for computer systems. But file corruption can occur in some instances. The cksum command in Linux helps us verify file integrity and weed out corrupted downloads and file transfers.

The worst part about file corruption is that it isn’t always readily noticeable. And there can be times where you’ll have no idea for days until you try to open a file and it doesn’t work. That’s where the cksum in Linux comes in handy.

We can utilize the cksum (short for checksum) command to display the CRC (Cyclic Redundancy Check) and byte counts of a file. We can effectively ascertain whether a not a file has been corrupted during a file transfer with this info.

An example of how we can use this information to tell whether or not a file is corrupted would be to compare the CRC of the file before and after the transfer. If they become different during this process, the file may have been corrupted.

In this tutorial you will learn:

  • How to use the cksum command on Linux

"<yoastmark

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software cksum
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Frequently Used Options



The cksum command displays, in its output, the Cyclic Redundancy Check number and the number of bytes in the file of your choosing that is passed to it. But you can also use the cksum command to check this information for multiple files at a time. We’ll cover that in the next couple of examples below.

One of the most common uses for the cksum command is to verify the integrity of a downloaded file. For example, when downloading a Linux distro ISO file, the checksum is usually displayed on the developer’s website. You can compare that checksum with your own (generated with the cksum command) to verify that you got the file as intended.

cksum command in Linux Basic Examples

  1. Running the cksum command followed by the name of a specified file will cause the command to print the CRC number and size in bytes of the file.
    $ cksum file01
    

    "Running

  2. As we mentioned earlier, we can also use the cksum command to display the CRC number and bytes of more than one file at a time. This allows for much more efficiency and speed than simply running the cksum command multiple times for each file name.
    $ cksum file01 file02 file03
    

    "Running

    As you can see in the screenshot above, the output will print the CRC number and bytes count of file03, file02, and file03

  3. As a bonus tip, you can couple the cksum command with the find command to search for files and output the CRC on each one. For example, the following command will search for all .txt files in the current working directory and all subdirectories, and run the cksum command on all that are found.
    $ find . -iname "*.txt" -exec cksum {} \;
    


NOTE
You can always use the man command to read more about the cksum command and its official documentation. Click the previous link to see how to open the manual pages for any command on a Linux system.

Closing Thoughts

In this tutorial, we learned all about the cksum command on Linux which is beneficial to master for general users and system administrators which is frequently used to transfer files on their system, and wish to verify the integrity of those files.