Last active
August 29, 2015 14:24
-
-
Save cympfh/e3a861bbbb0d0002e6a7 to your computer and use it in GitHub Desktop.
rename a file to its md5 (with its extension)
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 | |
if [ $# != 1 ]; then | |
echo 'usage: % <file>' | |
exit 0 | |
fi | |
MD5=md5 | |
which md5sum > /dev/null && MD5=md5sum | |
TARGET=$1 | |
EXT=${TARGET##*.} | |
which md5sum > /dev/null | |
if [ $? = 0 ]; then | |
HASH=`md5sum $TARGET | cut -d ' ' -f1` | |
else | |
HASH=`md5 $TARGET |awk '{print $NF}'` | |
fi | |
if [ $EXT = $TARGET ]; then # no extension? | |
echo mv $TARGET ${HASH} | |
mv $TARGET ${HASH} | |
else | |
echo mv $TARGET ${HASH}.${EXT} | |
mv $TARGET ${HASH}.${EXT} | |
fi |
Author
cympfh
commented
Jul 2, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment