How to use cksum command in Linux.

How To Use Cksum Command In Linux.

On Linux there are so many essential commands to perform various tasks or install the applications. One of the essential commands is cksum command which you can use to display a CRC (Cyclic Redundancy Check) value, the byte size of the file to standard output. In this article how you can use the cksum command in Linux.

You can follow the examples mentioned below to know how you can use cksum command in Linux:

To get the byte size and cksum of a text file execute the command by using the format given below:

cksum <file-name>

For example, I have executed the command using the above format of the file named as example.txt:

cksum example.txt

Now edit the file to change the data inside it by using the format given below:

sudo nano <file-name>

For example I have executed the command using the above format of the file named as example.txt to edit the data inside the file:

sudo nano example.txt

Executing the given below cksum command you can check the byte size of the edited file:

cksum example.txt

You can see the amount of data and checksum have changed than that of the previous file.

You can use cksum command for two files by using the command format mentioned below:

cksum <file name> <file name>

Using the format given above I have executed the following command to check the amount of data and checksum for the files example1.txt example2.txt:

cksum example1.txt example2.txt

As you know the cat command is used to read the data from a file, so when you execute the command by using the format given below, it reads data from the file and give you the checksum and data size of the file:

cat <file name> | cksum

I have used the example1.txt file to execute the command using the format given above:

cat example1.txt | cksum

When you execute the given below command on the command line terminal it will give you the option to write data of your choice:

cksum

You can also use the find command and cksum command together to list all the files in any directory and output the CRC on all the files in that directory by executing the command mentioned below:

find . -iname "*.txt" -exec cksum {} \;

 

About cksum Command Line Tool

You can check the version of cksum tool by executing the command given below:

cksum --version

You can check get the help of cksum tool by executing the command given below:

cksum --help

 

Conclusion

You can know the Cyclic Redundancy Check and byte size of a file by using cksum command.