对比两个目录中的文件改动

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/usr/bin/ruby
require 'set'

def rdiff (src_path, dst_path)

  if (File.exist?(src_path)) then
    path = src_path
  else
    path = dst_path
  end

  if (File.directory?(path)) then
    if (File.directory?(src_path)) then
      src_files = `ls  #{src_path}`.split()
    end
    if(File.directory?(dst_path)) then
      dst_files = `ls  #{dst_path}`.split()
    end
    files = Set[]

    if (src_files != nil) then
      src_files.each do |f|
        files.add(f)
      end
    end
    if (dst_files != nil) then
      dst_files.each do |f|
        files.add(f)
      end
    end

    files.each do |f|
      rdiff("#{src_path}/#{f}", "#{dst_path}/#{f}")
    end

  elsif (File.file?(src_path) and File.file?(dst_path)) then
    str = `diff #{src_path} #{dst_path}`
    if (str.size > 1) then
      print("---------- DIFF ----------\nSRC: #{src_path}\nDST: #{dst_path}\n#{str}\n\n")
    end
  else
    print("---------- DIFF ----------\nOnly File: #{path} exist\n\n")
  end
end

if (ARGV.size != 2) then
  print "\n*** Directory diff tool.\n      by suf.fnst\n"
  print "*** Please run as root.\n\n"
  print "Make sure only 2 args set.\n"
  print "usage: rdif DIR1 DIR2\n\n"
  exit -1
end

rdiff(ARGV[0], ARGV[1])