Skip to content

cksum command in Linux

The Linux cksum command is used to calculate a cyclic redundancy check (CRC) checksum for files. This checksum can be compared between systems to check for file integrity or changes. Additionally, cksum can also display the byte count of a file. By using the options available with cksum, users can control the output format and achieve the desired checksum calculation for their specific needs.

Terminal window
cksum [option] [file(s)]
OptionDescription
-helpDisplay a help message and exit
-bTreat input as binary
-hPrint the checksum and the number of bytes in the input file
ParameterDescription
file(s)The file(s) to calculate the checksum for
Terminal window
cksum file.txt

Calculate the checksum of the file “file.txt”.

Terminal window
cksum file1.txt file2.txt file3.txt

Calculate the checksum of multiple files simultaneously.

Terminal window
cksum -c checksums.txt

Verify the integrity of files listed in the checksums.txt file.

Terminal window
cksum -b file.txt

Generate the checksum of a file in binary format.

Terminal window
cksum -s file.txt

Display only the checksum value without filename.

Terminal window
cksum -n 100 file.txt

Generate checksum for the first 100 bytes of the file.

Terminal window
cksum -r folder/

Calculate checksum recursively for all files in a folder.

Terminal window
cksum -L file.txt

Calculate checksum with ignoring linefeed characters.

To use the cksum command in Linux, execute the following command:

Terminal window
cksum file.txt

How do I calculate a checksum for multiple files in Linux?

Section titled “How do I calculate a checksum for multiple files in Linux?”

To calculate the checksum for multiple files in Linux, you can use the following command format:

Terminal window
cksum file1.txt file2.txt file3.txt

How can I display the checksum value only in cksum?

Section titled “How can I display the checksum value only in cksum?”

You can display only the checksum value in cksum by using the following command:

Terminal window
cksum -s file.txt

How do I include the checksum byte count in the cksum output?

Section titled “How do I include the checksum byte count in the cksum output?”

To include the checksum byte count in the cksum output, you can use the following command:

Terminal window
cksum -o file.txt

How do I suppress the output of file names in cksum?

Section titled “How do I suppress the output of file names in cksum?”

To suppress the output of file names in cksum and only display the checksum and byte count, use the following command:

Terminal window
cksum -q file.txt

How can I verify the integrity of a file using cksum?

Section titled “How can I verify the integrity of a file using cksum?”

To verify the integrity of a file using cksum, you can compare the generated checksum with the original checksum. Here’s an example:

Terminal window
original=$(cksum file.txt | cut -d' ' -f1)
generated=$(cksum file.txt | cut -d' ' -f1)
if [ $original == $generated ]; then
echo "Integrity verified"
else
echo "Integrity check failed"
fi

How do I generate a checksum using a string input with cksum?

Section titled “How do I generate a checksum using a string input with cksum?”

To generate a checksum using a string input with cksum, you can use echo to pass the string and pipe it to cksum. Here’s an example:

Terminal window
echo "Hello, World!" | cksum

How can I recursively calculate checksums for all files in a directory in Linux?

Section titled “How can I recursively calculate checksums for all files in a directory in Linux?”

You can recursively calculate checksums for all files in a directory in Linux using the find command in combination with xargs and cksum. Here’s an example:

Terminal window
find /path/to/directory -type f | xargs cksum

How do I calculate the checksum without checking for ASCII control characters?

Section titled “How do I calculate the checksum without checking for ASCII control characters?”

To calculate the checksum without checking for ASCII control characters using cksum, you can use the following command:

Terminal window
cksum -B file.txt
  • Verifying data integrity
  • Checking for file corruption
  • Generating checksum values for files
  • Comparing checksum values for files
  • Detecting changes in files
  • Ensuring data consistency
  • Validating file transfer accuracy