Skip to content

Instantly share code, notes, and snippets.

@dyama
Created May 8, 2016 11:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dyama/bcba199d26c5324a08243054aeddd759 to your computer and use it in GitHub Desktop.
Save dyama/bcba199d26c5324a08243054aeddd759 to your computer and use it in GitHub Desktop.
md5name
#!/bin/sh
# coding: utf-8
if [ $# -gt 0 ]; then
for file in “$@”
do
if [ -f “$file” -a -s “$file” ]; then
# Get file extention
ext=`basename “$file” | sed ‘s/^.*\.\(.*\)$/\1/gi’`;
if [ “$file” == $ext ] ; then
ext=””;
else
ext=”.$ext”;
fi
# Make new file name
nfile=`dirname “$file”`/`md5sum “$file” | cut -c -32`$ext;
# echo $file to $nfile
mv “$file” $nfile
fi
done
else
cat <<EOUSG
md5name – Rename the file with md5sum string.
By dyama=members.fsf.org 2010.
Usage:
$0 File […]
EOUSG
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment