Skip to content

Instantly share code, notes, and snippets.

@kevinnio
Last active May 2, 2019 01:56
Show Gist options
  • Save kevinnio/bdd3a6be5707f5c0e7f27b92f1519875 to your computer and use it in GitHub Desktop.
Save kevinnio/bdd3a6be5707f5c0e7f27b92f1519875 to your computer and use it in GitHub Desktop.
Renames all files in the current dir using their MD5 checksums.
#! /bin/bash
md5 * | sed -e 's/MD5 (\([^.]*\)\(.[^)]*\)) = \(.*\)$/mv -v "\1\2" \3\2/' | sh
#! /usr/bin/env ruby
require 'digest/md5'
def rename_file(file)
old_name = File.basename(file)
new_name = Digest::MD5.hexdigest(file.read) << File.extname(file)
File.rename(file, new_name)
puts "#{old_name} => #{new_name}"
end
# Script starts!
files = Dir.glob("*.{jpg,jpeg,png,gif}") # Currently limited to images!
files.each { |file| rename_file File.open(file) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment