4 Find duplicate files in given directory trees. Where "duplicate" is defined as
5 having the same MD5 hash digest.
7 It is roughly equivalent to the following one-liner:
9 find . -type f -exec md5sum '{}' \; | awk '{paths[$1, ++cnt[$1]] = $2} END {for (path in cnt) {n = cnt[path]; if (n > 1) {print(path, n); for (i=1; i<=n; i++) {print(" ", paths[path, i])} } } }'
12 which, when indented, looks like:
14 find . -type f -exec md5sum '{}' \; \
17 paths[$1, ++cnt[$1]] = $2
24 for (i=1; i<=n; i++) {
25 print(" ", paths[path, i])
32 and works well-enough, until you start getting weird file paths that are more
33 of a pain to handle quoting for than re-writing this thing in OCaml :)
37 After building, run `dups` on the current directory tree:
41 Finished, 0 targets (0 cached) in 00:00:00.
42 Finished, 5 targets (0 cached) in 00:00:00.
45 df4235f3da793b798095047810153c6b 2
48 d41d8cd98f00b204e9800998ecf8427e 2
51 087809b180957ce812a39a5163554502 2
52 "./_build/dups.native"
54 Processed 102 files in 0.025761 seconds.
56 Note that the report line (`Processed 102 files in 0.025761 seconds.`) is
57 written to `stderr`, so that `stdout` is safely processable by other tools.