-
-
Save danopia/237466 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'digest/md5' | |
require 'find' | |
@hashfun = Digest::MD5.new | |
@digests = {} | |
def digest filename | |
@hashfun.hexdigest File.read(filename) | |
end | |
def checkdup base, filename | |
hash = digest filename | |
filename.sub! base, '' if filename.index(base) == 0 | |
if @digests.has_key? hash | |
old = @digests[hash].first | |
old += " (plus #{@digests[hash].size - 1} others)" if @digests[hash].size > 1 | |
puts "#{filename} and #{old} are duplicates." | |
@digests[hash] << filename | |
else | |
@digests[hash] = [filename] | |
end | |
end | |
bases = ARGV | |
if bases.empty? | |
print "Enter dir name to search: " | |
bases << gets.chomp | |
end | |
one_base = bases.size == 1 | |
bases.each do |base| | |
Find.find base do |path| | |
checkdup( (one_base ? base : ''), path) unless File.directory? path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment