Created
April 20, 2016 03:29
-
-
Save LeiHao0/fef7567f600af2ad3457651a1d579ad7 to your computer and use it in GitHub Desktop.
Find duplicate Files (file < 4G)
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 | |
| # 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