Created
June 29, 2012 09:18
-
-
Save jaspervdj/3016875 to your computer and use it in GitHub Desktop.
Remove all file duplicates in a directory, based on file content
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/ruby | |
require 'digest' | |
require 'fileutils' | |
entries = Dir.entries('.').select { |x| File.file? x } | |
hashes = {} | |
entries.each do |entry| | |
hash = Digest::MD5.file(entry).to_s | |
if hashes[hash] | |
puts "Removing #{entry} (duplicate of #{hashes[hash]})" | |
FileUtils.rm entry | |
else | |
hashes[hash] = entry | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment