Last active
November 4, 2023 04:40
-
-
Save rlcamp/1ce6444fa89600aafa11d80cafdf4718 to your computer and use it in GitHub Desktop.
find files in adjacent directories with the same filenames and different contents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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