Sha256: 6523c7d509a6c585e81100eaee4e6ec9794de94f78b79067f3ec1db723e4e53e

Contents?: true

Size: 843 Bytes

Versions: 79

Compression:

Stored size: 843 Bytes

Contents

#!/usr/bin/env ruby

require 'utils'
require 'tins/find'
include Utils::MD5

def find_same(*paths)
  files = Hash.new { |h,k| h[k] = {} }
  Tins::Find.find(*paths) do |filename|
    file_stat = File.stat(filename)
    if file_stat.file?
      size = file_stat.size
      $DEBUG and warn "Encountered '#{filename}' (#{size} bytes)."
      files[size][filename] = true
    end
  end

  files = files.inject({}) do |h, (_,fs)|
    keys = fs.keys
    if keys.size >= 2
      keys.each { |k| h[k] = true }
    end
    h
  end.keys

  md5s = Hash.new { |h,k| h[k] = [] }
  for filename in files
    md5sum = md5 filename
    md5s[md5sum] << filename
  end
  files = md5s.values
  files.reject! { |fs| fs.size < 2 }
  files
end

puts find_same(*ARGV).map { |fs| [ fs.size, fs ] }.sort.map { |c, fs|
  "#{c}\t#{fs.sort.map { |f| "'#{f}'" } * "\t"}"
}

Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
utils-0.0.67 bin/same_files
utils-0.0.66 bin/same_files
utils-0.0.65 bin/same_files
utils-0.0.64 bin/same_files
utils-0.0.63 bin/same_files
utils-0.0.62 bin/same_files
utils-0.0.61 bin/same_files
utils-0.0.60 bin/same_files
utils-0.0.59 bin/same_files
utils-0.0.58 bin/same_files
utils-0.0.57 bin/same_files
utils-0.0.56 bin/same_files
utils-0.0.55 bin/same_files
utils-0.0.54 bin/same_files
utils-0.0.53 bin/same_files
utils-0.0.52 bin/same_files
utils-0.0.51 bin/same_files
utils-0.0.50 bin/same_files
utils-0.0.49 bin/same_files