Thursday, 25 June 2015

Comparing Files using Find and CMP

I needed to compare two directories containing binary files. Rsync was confusing, Diff only compares text-files.

I tried the following:
#!/bin/bash
# Example: ~/compare.sh FC30-3DA9
# where $1 is the directory name
# requirement: you are in one of the two parent dirs.
# the directories to compare must have the same name

find $1 -type f -exec sh -c '
  for f; do
    cmp "$f" /directory/of/mr/bear/"$f"
  done
' sh {} +
Seemed to work fine.

References

How to compare files in two folders using cmp?
http://www.unix.com/shell-programming-and-scripting/144821-how-compare-files-two-folders-using-cmp.html

No comments:

Post a Comment