How to verify files copied with hashes computed using hashdeep on Linux

Linux is very meticulous about maintaining the integrity of files and the file system when copying files across folders.

However, there are occassions when the copies of files need to be verified with those of the original. To do this, hashdeep is a good tool to compute hashes of files copied and compare them with the originals.

First of all, open a terminal window and install hashdeep as follows:
$ sudo apt-get install hashdeep <enter>

My original folder was in ~/MyFolder. I copied the files from ~/MyFolder to ~/MyNewFolder using the cp -r command in Linux.

Now, to verify that ~/MyFolder and ~/MyNewFolder are the same, do the following:
$ hashdeep -c MD5 -e -r -l ~/MyFolder > ~/checksum.md5 <enter>

The above command is used to create a file checksum.md5 that will contain the checksums of all files recursively within all the folder in ~/MyFolder.

-c MD5 tells hashdeep that we want to compute MD5 hashes
-e to compute the estimated time on large files
-r recursively go through all sub-folders in the ~/MyFolder folder
-l display the hashes with the relative path. This to help matching

Now, to verify that the files in ~/MyNewFolder are identical to those in ~/MyFolder, use the following command:
$ hashdeep -c MD5 -e -r -l -k ~/checksum.md5 -x ~/MyNewFolder <enter>

The above command computes the MD5 hash for all files in all folders in ~/MyNewFolder and displays those files which do not match to the checksums in the checksum.md5 file.

-c MD5 tells hashdeep that we want to compute MD5 hashes
-e to compute the estimated time on large files to generate the hash
-r recursively go through all sub-folders in the ~/MyNewFolder folder
-l display the hashes with relative paths to aid matching.
-k checksum.md5 contains checksums of all files to be compared to files in ~/MyNewFolder
-x displays only those files where the checksums are different.

To display all files where checksums are identical, use -m in place of -x.

hashdeep is a powerful command that can be used to prove and protect the integrity of files copied from one folder or device to another folder or device.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s