I am creating a website and I would like the hash file names of my images.
How to create a bash script file that renames every file in a directory using sha1 old file name?
I tried:
#!/bin/bash for file in * do if [ -f "$file" ];then newfile="openssl sha1 $file" mv "$file" $newfile" fi done
But this does not work :(
EDIT
Based on the suggestions here, I tried this:
#!/bin/bash for file in old_names/* do if [ -f "$file" ];then newfile=$(openssl sha1 $file | awk '{print $2}') cp $file new_names/$newfile.png fi done
This renames the files, but I'm not sure what was used to hash the file name. Has the expansion increased? made a way?
INFO
Then I will use the PHP sha1 () function to display the images:
echo "<img src=\"images/".sha1("$nbra-$nbrb-".SECRET_KEY).".png\" />\n";
Manu
source share