Skip to content

Instantly share code, notes, and snippets.

@LeiHao0
Created April 20, 2016 03:29
Show Gist options
  • Select an option

  • Save LeiHao0/fef7567f600af2ad3457651a1d579ad7 to your computer and use it in GitHub Desktop.

Select an option

Save LeiHao0/fef7567f600af2ad3457651a1d579ad7 to your computer and use it in GitHub Desktop.
Find duplicate Files (file < 4G)
#!/usr/bin/env ruby
# Usage
# ruby DumpFiles.rb ~/$DirPath
require 'digest/md5'
require 'find'
path = ARGV[0]
path = './' if !path
dict = {}
Find.find(path) do |f|
if File.file?(f) && f =~ /.*\.*/
checksum = Digest::MD5.hexdigest(File.read(f))\
print "checking: ", f, "\n"
if dict.has_key?(checksum)
dict[checksum] = dict[checksum].push(f)
else
dict[checksum] = [f]
end
end
end
dict.each do |k, v|
print v, "\n" if v.count > 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment