Re: Trying to compare files in two directories with checksum



EyeHaveNoName wrote:
On Feb 14, 1:23 pm, Cyrus Kriticos <cyrus.kriti...@xxxxxxxxxxxxxx>
wrote:
EyeHaveNoName wrote:

I have a need to go through about 6TB of data and compare the files in
one directory to the files in another. The need arose because all of
these files were copied from point A to point B, and now we need to
validate that there has been no corruption. I am thinking that cksum
will work, these are graphics files.
I understand how to find all the files and run a command on them, but
I am at a loss as to how I can :
1) For each file name in /mount/directory...
2) Compare that file with the same name in /other_mount/directory
using cksum. i.e.
$ cksum /mount/directory/file1 /other_mount/directory/file1
sum1=$(md5sum -b "/mount/directory/file1")
sum2=$(md5sum -b "/other_mount/directory/file1")

if [ "${sum1% *}" = "${sum2% *}" ]; then echo ok; else echo not ok; fi

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.

Thanks, this is helpful. But I am not sure it will work for me. This
only works when I know the file name; there are thousands (or millions
for all I know) of files in these directories that need to be parsed,
and they are all under fairly deep directory structures. I suppose I
could run a find on each dir. first, then feed the output into this?

You wrote "I understand how to find all the files and run a command on them".

--- comparefiles.sh ---
#!/bin/bash

prefix1="/mount/directory/file1" # without trailing /
prefix2="/other_mount/directory/file1" # without trailing /

find "$prefix1" -type f | while read filename; do

name="${filename#$prefix1*}"
sum1="$(md5sum -b "$prefix1$name")"
sum2="$(md5sum -b "$prefix2$name")"

if [ "${sum1% *}" = "${sum2% *}" ]; then
echo "ok: $prefix1$name"
else
echo "not ok: $prefix1$name"
fi

done
--- comparefiles.sh ---

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
.



Relevant Pages

  • Re: Trying to compare files in two directories with checksum
    ... Best regards | Be nice to America or they'll bring democracy to ... echo "not ok: $prefix1$name" ...
    (comp.unix.shell)
  • Re: PHP?
    ... Best regards | Be nice to America or they'll bring democracy to ...
    (de.comp.os.unix.linux.misc)
  • Re: Laptop-Display statt Beamer
    ... Was soll eigentlich der Quatsch Deine Postings mit einem Sig-Trenner "-- " anzufangen? ... Best regards | Be nice to America or they'll bring democracy to ...
    (de.comp.os.unix.linux.misc)
  • Re: pathname expansion in for-Schleife
    ... $ echo "$ref" ... Best regards | Be nice to America or they'll bring democracy to ...
    (de.comp.os.unix.shell)
  • Re: cut digit from right side
    ... solution in combination with "echo $RANDOM" is the best of both ... Best regards | Be nice to America or they'll bring democracy to ...
    (comp.unix.shell)