
Show HN: Safely rename files to their SHA1 sum + ext on FreeBSD 11 - eriknstr
I have a collection of files with external origin which had bad names. The worst characters that they contained were some UTF-8 characters and the single quotation mark. Aside from these characters, there were other unwanted characters such as spaces in the file names. For this collection of files, because I use the metadata that is inside of the files to organize them, I don&#x27;t care so much what the files are called, as long as they don&#x27;t contain non-ASCII, non-printable or other troublesome characters.<p>I wrote a script for FreeBSD 11 to safely rename such files to be named by their own SHA1 hash sum plus their original extension. (Files with bad characters in extension are made extension-less.)<p>Here is the script: https:&#x2F;&#x2F;github.com&#x2F;eriknstr&#x2F;utils&#x2F;blob&#x2F;master&#x2F;shaname.sh<p>I have commented the script in detail so that readers may quickly see what&#x27;s going on and which assumptions are made, so that they may determine whether the script is appropriate for their use-case.<p>I reiterate that the script was written for FreeBSD 11 and should not be used on platforms with commands that have incompatible arguments.<p>The script is released under the ISC license.<p>Pull requests are welcome.
======
eriknstr
Clickable URL:
[https://github.com/eriknstr/utils/blob/master/shaname.sh](https://github.com/eriknstr/utils/blob/master/shaname.sh)

