Calculate Filename SHA1 with Ruby

Basic usage Where FILENAME is the filename that you want to calculate require 'digest/sha1' Digest::SHA1.hexdigest(FILENAME) More advanced usage Save this code as checkhash.rb, usage: checkhash.rb <filename>. require 'digest/sha1' # Usage: checkhash.rb <filename> filename = ARGV.pop if filename.nil? # if no filename specified then prints help puts 'Please specify the filename to calculate the hash' puts "Usage: #{File.basename($PROGRAM_NAME)} FILENAME" exit end # calculating SHA1 hash def calculate_hash(file) Digest::SHA1.hexdigest(file) end file_hash = calculate_hash(filename) puts "#{filename}: #{file_hash}"

<span title='2018-02-22 17:05:20 +0000 UTC'>February 22, 2018</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;Franccesco Orozco