Skip to content

Instantly share code, notes, and snippets.

@arosemena
Created November 21, 2018 21:54
Show Gist options
  • Save arosemena/e693249423e2ca12ba9740220b968398 to your computer and use it in GitHub Desktop.
Save arosemena/e693249423e2ca12ba9740220b968398 to your computer and use it in GitHub Desktop.
renames files in the directory to their sha1 checksums keeping the extension
#!/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
@Matt-Deacalion
Copy link

This is brilliant. Thanks for sharing. I used it to sort out all of my random .txt files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment