Last active
May 2, 2019 01:56
-
-
Save kevinnio/bdd3a6be5707f5c0e7f27b92f1519875 to your computer and use it in GitHub Desktop.
Renames all files in the current dir using their MD5 checksums.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
md5 * | sed -e 's/MD5 (\([^.]*\)\(.[^)]*\)) = \(.*\)$/mv -v "\1\2" \3\2/' | sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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