Skip to content

Instantly share code, notes, and snippets.

@mu373
Created July 7, 2021 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mu373/962c239b7ba37132f15901c75b3dd2e4 to your computer and use it in GitHub Desktop.
Save mu373/962c239b7ba37132f15901c75b3dd2e4 to your computer and use it in GitHub Desktop.
ファイルのハッシュ値を計算してリネームする
#/bin/zsh
set -e
IFS=$'\n'
filePath=$1
fileDir=`dirname $filePath`
fileName=`basename $filePath`
fileExt=`echo $fileName | sed -r 's/(.*)(\.[^\.]*$)/\2/'`
# 拡張子を持たないファイルのための処理
if [ $fileName == $fileExt ]; then
echo "no extension"
fileExt=""
fi
# ハッシュ値を計算
hashOfFile=`sha3sum -a 512 $1 | cut -d " " -f 1`
newFileName=$hashOfFile$fileExt
newFilePath=$fileDir/$newFileName
mv $filePath $newFilePath
echo "Original file name: " $fileName
echo "New file name:" $newFileName
echo "Hash Algorithm: SHA3-512"
# ログは~/Library/Logs/hashRename.logに出力
echo \""$filePath"\""\t"\""$newFilePath"\" >> ~/Library/Logs/hashRename.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment