Skip to content

Instantly share code, notes, and snippets.

@bluegraybox
Created May 13, 2016 17:09
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 bluegraybox/228fc0ab333d2268f16e3b73c0cc2c36 to your computer and use it in GitHub Desktop.
Save bluegraybox/228fc0ab333d2268f16e3b73c0cc2c36 to your computer and use it in GitHub Desktop.
Ruby script to find duplicate files
#!/usr/bin/ruby -w
require 'find'
require 'md5'
dir = ARGV[0]
dir = "." unless dir
digests = {}
Find.find( dir ) do |f|
if File.file?( f ) and File.size?( f ) then
d = MD5.file( f ).hexdigest
if digests[d] then
puts "Duplicates: #{digests[d]} and #{f}"
else
digests[d] = f
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment