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.
Overview
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
command:
$ cksum myfile.txt
123456789 100 myfile.txt
In this example, 123456789
is the checksum value for myfile.txt
, 100
is the number of bytes in the file, and myfile.txt
is the name of the file.
Specific use cases
- Verifying file integrity:
cksum
can 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,
cksum
can be used to identify duplicate files. If two files have the same checksum value, they are identical in content.
Options
The cksum
command has a few options that can be used to modify its behavior. Here’s a table of the available options:
Option | Description |
---|---|
-b |
Output in binary mode |
-o n |
Specify the starting value for the checksum calculation |
-r |
Use the BSD algorithm instead of the POSIX algorithm |
-t |
Output in tab-separated format |
Troubleshooting tips
- 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.
- If
cksum
returns an error message, make sure that you have permission to read the file.
Notes
- The checksum value generated by
cksum
is not a guarantee that the file is error-free. It is only a means of detecting whether the file has been modified or corrupted. cksum
uses the POSIX algorithm by default, but can use the BSD algorithm with the-r
option. The BSD algorithm is faster but less reliable than the POSIX algorithm.