Created
November 21, 2018 21:54
-
-
Save arosemena/e693249423e2ca12ba9740220b968398 to your computer and use it in GitHub Desktop.
renames files in the directory to their sha1 checksums keeping the 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 | |
# Renames all the files in the current directory | |
# to their sha1 checksums keeping the extension | |
# it prints the list of the converted files at | |
# the end | |
# Requires the shasum command that comes with xcode | |
ls | |
read -r -p "Continue? (yes/no): " continue | |
# Exit if not confirmed | |
if ! [[ ${continue} =~ (yes) ]]; then exit 1; fi; | |
for i in *; do | |
sha1=`shasum "$i" 2>/dev/null | awk '{split($0, a); print a[1]}'` | |
extension=`echo "$i" | awk '{print a[split($0, a, ".")]}'` | |
# Rename the file | |
mv "$i" "$sha1.$extension" | |
# Print the reference | |
echo "$sha1 < $i" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is brilliant. Thanks for sharing. I used it to sort out all of my random
.txt
files.