Ubuntu: Check several files with MD5


Every month, a company sends me a hard drive - ext4 encrypted with cryptsetup - with backup files from a server. In that drive there are 1000+ files, and they almost fill up a 2Tb HDD. Each file has a corresponding .md5 file so we can check the integrity of it, but as you could imagine, I can't check every single one of them by hand in terminal, so I copy them to another hard drive and check them in Windows. On Ubuntu is there any way to check all files, or even just all files in a folder? Thanks.


Yes, you can. Assuming every file has just a md5 file in the same directory with just a appending .md5, create a script file (e. g. md5check.sh) with following content:

#!/bin/bash  echo "Building file list..."  $ALLFLS="$(find)"  echo "Checking all files..."  for word in $ALLFLS; do      if [[ $(cat "$word.md5") == $(md5sum -b "$word") ]]; then          echo "$word OK"      else          echo "MD5 wrong for $word"          exit      fi  done  echo "All files correct!"  

This checks if every file. Please report if it worked. (Make sure you have changed the directory to your hard drive before executing the script and make sure you have chmod +x it)


You can also check this page.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »