cksum is a Linux command that checks the CRC (Cyclic Redundancy Check) of a file to ensure that it is correct. It calculates a checksum value for a file, which is a numerical representation of the file’s contents. This value can be used to verify that a file has not been corrupted or modified in any way.
The basic syntax for the
cksum command is as follows:
cksum [OPTION]... FILE...
The command takes one or more file names as arguments and calculates the checksum value for each file. The output consists of three columns: the checksum value, the number of bytes in the file, and the file name.
Here’s an example of how to use the
$ cksum myfile.txt 123456789 100 myfile.txt
In this example,
123456789 is the checksum value for
100 is the number of bytes in the file, and
myfile.txt is the name of the file.
Specific use cases
- Verifying file integrity:
cksumcan be used to verify that a file has not been corrupted or modified in any way. By comparing the checksum value of a file before and after it is transferred or copied, you can ensure that the file has not been altered in transit.
- Identifying duplicate files: Since each file has a unique checksum value,
cksumcan be used to identify duplicate files. If two files have the same checksum value, they are identical in content.
cksum command has a few options that can be used to modify its behavior. Here’s a table of the available options:
||Output in binary mode|
||Specify the starting value for the checksum calculation|
||Use the BSD algorithm instead of the POSIX algorithm|
||Output in tab-separated format|
- If the checksum value does not match the expected value, the file may be corrupted or modified. Try transferring or copying the file again to ensure that it is not altered in transit.
cksumreturns an error message, make sure that you have permission to read the file.
- The checksum value generated by
cksumis not a guarantee that the file is error-free. It is only a means of detecting whether the file has been modified or corrupted.
cksumuses the POSIX algorithm by default, but can use the BSD algorithm with the
-roption. The BSD algorithm is faster but less reliable than the POSIX algorithm.