![]() |
VOOZH | about |
The cksum command in Linux is used to verify file integrity by calculating a CRC (Cyclic Redundancy Check) value along with the file size. It is mainly used to detect accidental corruption during file transfer or storage.
This example shows how to calculate the checksum of a file.
cksum file.txtOutput :
Explanation:
You can calculate CRC values for multiple files in one command.
cksum file1.txt file2.txt file3.txtNote: Each file is processed separately, and the output is displayed line by line for each file.
If no file name is provided, cksum reads data from standard input.
echo "Hello Linux" | cksumNote: Useful for verifying the integrity of piped data or command output.
You can redirect the output of cksum to a file for later comparison.
cksum file.txt > file_checksum.txtNote: Stores the CRC value and file size, which can be reused to check file consistency later.
This example compares the current checksum with a previously saved one.
cksum file.txt | diff - file_checksum.txtNote: If no output is produced, the file has not changed. If output is shown, the file content has changed.
cksum [OPTION]... [FILE]...The cksum command provides very limited options compared to other checksum utilities.
Displays help information and usage details.
cksum --help👁 ImageNote: Helpful when you want a quick reference for command usage.
Displays the version information of the cksum utility.
cksum --version👁 ImageNote: Useful for debugging or checking compatibility across systems.
After transferring large files over a network, compare CRC values to ensure no accidental corruption occurred.
cksum backup.tarNote: Run this command before and after transferring the file, If both CRC values match, the file was transferred successfully.
Helps confirm that backup files remain unchanged after creation.
cksum backup_2024.tarNote: This command can be stored in logs or scripts and rechecked later to validate backups.
Used to monitor important files and detect unintended changes over time.
cksum config.cfgNote: If the CRC value changes unexpectedly, it indicates accidental modification.