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.22.1 bin/same_files
utils-0.22.0 bin/same_files
utils-0.21.2 bin/same_files
utils-0.21.1 bin/same_files
utils-0.21.0 bin/same_files
utils-0.20.0 bin/same_files
utils-0.19.0 bin/same_files
utils-0.18.1 bin/same_files
utils-0.18.0 bin/same_files
utils-0.17.0 bin/same_files
utils-0.16.0 bin/same_files
utils-0.15.1 bin/same_files
utils-0.15.0 bin/same_files
utils-0.14.0 bin/same_files
utils-0.13.0 bin/same_files
utils-0.12.0 bin/same_files
utils-0.11.0 bin/same_files
utils-0.10.1 bin/same_files
utils-0.10.0 bin/same_files
utils-0.9.0 bin/same_files