#!/usr/bin/env ruby
#This is dirty ruby script but function well though.
#More with " https://github.com/ohyoungjooung2/ruby_scripts/blob/master/same_file.rb"
#^^; Have fun.
files=`find . -type f | xargs stat -c "%s %n"`
s=files.split("\n")
#p s
sk=[]
sv=[]
i=0
s_size=s.size
while i < s_size
sk<<s[i].split(" ")[1]
sv<<s[i].split(" ")[0]
i+=1
end
# files name as a array sk
#p sk
#puts ""
# files size as a array sv
#p sv
#Creating hash
j=0
h={}
#puts "sv size is #{sv.size}"
#puts "s_size is #{s_size}"
while j < sv.size
#puts j
h[sk[j]]=sv[j]
j+=1
end
#Putting h hash
#puts h
z=0
#Getting uniq values of each hash value
u=h.values.uniq
while z < h.size
# puts z
same_files=h.select { |k,v| v==u[z] }
if same_files.size >= 2
fs=0
while fs < same_files.size
puts "same_file size with #{u[z]} bytes are #{same_files.keys[fs]}"
fs+=1
end
end
z+=1
end
young@ubuntu-16:~/test$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
young@ubuntu-16:~/test$ chmod 700 same_file.rb
young@ubuntu-16:~/test$ ./same_file.rb
same_file size with 8941 bytes are ./1
same_file size with 8941 bytes are ./2
same_file size with 548 bytes are ./apparmor.d/abstractions/ibus
same_file size with 548 bytes are ./f.sh
same_file size with 1748 bytes are ./tttt/iiii
same_file size with 1748 bytes are ./tttt/inputrc
same_file size with 1748 bytes are ./inputrc
same_file size with 1654 bytes are ./tttt/pass
same_file size with 1654 bytes are ./tttt/passwd
same_file size with 1654 bytes are ./pass
same_file size with 1654 bytes are ./passwd
same_file size with 1654 bytes are ./ssap
same_file size with 26 bytes are ./tttt/iss
same_file size with 26 bytes are ./tttt/issue2
same_file size with 26 bytes are ./issue
same_file size with 364 bytes are ./tttt/rrrr
same_file size with 364 bytes are ./rc.local
same_file size with 738 bytes are ./same_file.rb
same_file size with 738 bytes are ./groff/man.local
No comments:
Post a Comment