Skip to content

Instantly share code, notes, and snippets.

@manveru
Created November 2, 2010 06:13
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 manveru/659309 to your computer and use it in GitHub Desktop.
Save manveru/659309 to your computer and use it in GitHub Desktop.
# Encoding: BINARY
require "digest/md5"
abort "usage #$0 path1 [path2] [path3] ..." if ARGV.empty?
hashes = Hash.new{|h,k| h[k] = [] }
roots = ARGV.map{|arg| File.expand_path(arg) }.uniq
roots.each do |root|
glob = File.join(root, '/**/*')
Dir.glob glob do |path|
next unless File.file?(path)
puts "Analyzing #{path}"
hash = Digest::MD5.hexdigest(File.read(path).encode!)
hashes[hash] << path
end
end
hashes.each do |hash, paths|
next if paths.size < 2
puts "\nDuplicate files with checksum: #{hash}", *paths
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment