This guide provides a comprehensive introduction to the Linux ‘sum’ command, covering its history, usage, parameters, and common use cases. The ‘sum’ command, a part of GNU Core Utilities, is used to calculate a simple checksum of files, primarily for verifying file integrity. This guide also explores some of the command’s lesser-known functionalities and key precautions to be aware of when using it.
Instructions
This article provides a comprehensive introduction to the Linux ‘sum’ command for beginners. We will delve into its history, usage, parameters, and most common use cases. Additionally, we will explore some of its less-known functionalities and necessary precautions while using this command.
History
The ‘sum’ command is a part of GNU Core Utilities, available in Unix-like operating systems, including Linux. It has been designed to compute and print a checksum for each input file, enabling users to verify the integrity of files.
When and why to use it
The ‘sum’ command is used to calculate a simple checksum of files. This comes in handy when you want to ensure the integrity of a file after a transfer or when you want to detect unwanted changes in a file.
How to use it
To use the ‘sum’ command, simply type ‘sum’ followed by the filename in the command line.
sum filename.txt
The commonly used parameters
While ‘sum’ is a simple command, it does have some useful parameters:
-r
Use BSD sum algorithm, use 1K blocks
sum -r filename.txt
-s
or--sysv
Use System V sum algorithm, use 512 bytes blocks
sum -s filename.txt
Other supported parameters
-h
or-help
: Display a help message and exit.-v
or-version
: Output version information and exit.
Most common use cases
One of the most common use cases for ‘sum’ is verifying file integrity after transferring a file between different systems. By comparing the sum of the file before and after the transfer, you can confirm whether the file has been transferred correctly.
sum filename.txt
The tricky skills
While ‘sum’ is a relatively simple command, it can be combined with other commands for more complex operations. For example, you can pipe the output of ‘sum’ into ‘awk’ to print only the checksum, excluding the block count.
sum filename.txt | awk '{print $1}'
What needs to be noted
Keep in mind that ‘sum’ is not as reliable as other checksum tools like ‘sha256sum’ or ‘md5sum’ for checking file integrity, especially for critical operations. The ‘sum’ command computes a simple checksum which is more prone to collisions, where different files produce the same checksum.
Conclusion
The ‘sum’ command is a simple, useful tool in the Linux command-line arsenal, suitable for performing basic file integrity checks. While it does not offer the level of reliability that other, more complex checksum tools provide, its simplicity and ease of use make it an excellent choice for quick checks and simple use cases.