Skip to content

Instantly share code, notes, and snippets.

@rlcamp
Last active November 4, 2023 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlcamp/1ce6444fa89600aafa11d80cafdf4718 to your computer and use it in GitHub Desktop.
Save rlcamp/1ce6444fa89600aafa11d80cafdf4718 to your computer and use it in GitHub Desktop.
find files in adjacent directories with the same filenames and different contents
#!/bin/sh
find . -type f \( -name '*.c' -o -name '*.h' -o -name '*.py' \) \
-not -name 'main*' \
-not -name '__init__.py' \
-not -name 'version.h' \
-not -name 'ViewController.h' \
-not -name 'AppDelegate.h' \
-not -name 'test.c' \
-not -name 'config.h' -exec cksum {} + |
python3 -c '
import os, sys, bisect, zlib, re
out = []
for line in sys.stdin:
hash, size, path = line.split()
name = os.path.basename(path)
path = re.sub("\./", "", path)
out.append((name + " " + str(os.stat(path).st_mtime), hash, path, name))
out.sort(reverse=True)
hashes_and_paths = {}
for key, hash, path, name in out:
prior_hash, prior_path = hashes_and_paths.get(name, (None, None))
if prior_hash is not None and prior_hash != hash:
print("\033[31;1mwarning:\033[0m diff %s %s" % (path, prior_path))
hashes_and_paths[name] = (hash, path)
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment