Linux Commands

Linux Sha1sum Command

The computer software that is used to validate and calculate the SHA-1 hashes is known as sha1sum. SHA-1 stands for Secure Hash Algorithm 1. It’s a tool that’s widely used to check the integrity of files. SHA-1 is a cryptographically broken but still frequently used hash function that receives input and generates a 160-bit or 20-byte long hash value, which is known as a message digest, which is typically displayed as a 40-digit long hexadecimal number. SHA-1 is still commonly used to validate files, even though it is no longer considered secure against adversaries. In this article today, we will let you know about what the sha1sum command is and how you can use it.


sha1sum [OPTION] [FILE_NAME]

We can use multiple flags in the option of this command to check and verify the validity of the file. The first step is to open a terminal on the operating system (Linux/Unix/Ubuntu). We have been using the Kali Linux system. To begin, we must navigate to a specific directory containing the required file against which the checksum will be verified. After that, you can use the ls (list directory) command to see if any files or folders exist in the directory. As you can see, our current directory (works) has several files and folders. As an alternative, after the sha1sum command, type the whole directory path together with the file name.

$ ls

Get the SHA-1 of a file on the terminal screen

Let’s get the checksum value for the particular text file from the current working directory. For this, you need to enter the shown-below command in the Linux terminal to retrieve the checksum value or validate the new.txt file. This command prints the file’s SHA-1 checksum along with the name of the text file on the terminal screen for which the checksum is desired. You can see the checksum is displayed along with the file “new.txt”.

$ sha1sum new.txt

In the same way, we have a checksum for another text file, newfile.txt. The same sha1sum command shown below has been used to display the checksum for this TEXT file.

Method to Write the SHA-1 of a file

The SHA-1 of a file can be written using a standard shell redirection procedure. An SHA-1 file should be sent along with the file new.txt if it is to be sent over the Internet. Anyone who is downloading or reading the file can simply verify (to some extent) that it has not been tampered with in this way by using this SHA-1 file. The sha1sum command is used along with the filename followed by the greater than sign “>” and the new file name to generate the SHA-1 file and then write the checksum in the SHA-1 file.

$ sha1sum new.txt > new.sha1

Using the cat command, we may create single or multiple files, read file content, concatenate the text of multiple files, and send data to the terminal or files. In our situation, we use the cat command to display the checksum value within the SHA-1 file that we have just created on the terminal. This displays the checksum as well as the file name against which it was generated.

$ cat new.sha1

Using the VIM editor, we have updated the contents of the new.txt file. After that, we executed the sha1sum command with the –c switch option to test the file’s integrity. It returns a warning that the file’s checksum does not match, indicating that the file has been modified.

$ vim new.txt
$ sha1sum -c new.sha1

After that, we updated the SHA-1 file against the new.txt file. When we re-run the script with the –c switch without editing or modifying the file, it returns OK, indicating that there has been no change to the file and that it is safe and intact. The output has been shown below.

$ sha1sum new.txt > new.sha1
$ sha1sum -c new.sha1

By default, the sha1sum tool reads a file in text format, but we can forcefully change the command’s capabilities to read in binary mode. We use the -b switch option after the sha1sum command to read in the binary mode. The command in the image shows the checksum of a file.

$ sha1sum -b new.sha1

The binary SHA-1 and the text of the new.txt file are the same after comparison in the image attached below which contains both the commands.

$ sha1sum -b new.sha1
$ sha1sum new.txt

The sha1sum command can also be used to check the checksum value of an SHA-1 file by typing the same command. The sample below provides a screen that displays the SHA-1 file’s checksum. The thing you must notice is that the checksum of the SHA-1 file has now changed.

$ sha1sum new.sha1

When we open the SHA-1 file in the VIM Editor, the checksum is displayed along with the file name.

$ vim new.sha1

To get the exact details, run the sha1sum command using the –help switch to get more information about the command. The sh1sum command with its options information is displayed in the output of the help command shown in the image.

$ sha1sum - -help

Things move quickly when it comes to security issues. The hashing algorithm md5 is now commonly regarded as unsafe. It’s also anticipated that the sha1 hashing technique would be insecure. As a result, new algorithms are predicted to arise and become widely employed in the future. Many checksum procedures are already included with Linux/Linux/Ubuntu, and it is hoped that this will keep growing. As you can see in the screenshot below, if we input the command sha and press enter in the Linux Terminal, we get a list of other sha-related commands that can be used instead of sha1sum.

$ sha


This is about using the sha1sum command to display the checksum of a specific text of the sha-1 file in the Kali Linux shell. We hope, this article will be a great help to new Linux users and get the desired level of understanding. All these commands can be implemented on any operating system.

About the author

Omar Farooq

Hello Readers, I am Omar and I have been writing technical articles from last decade. You can check out my writing pieces.