all files in the folder disappeared because of a typo while using `mv`

Solution 1:

Probably not. Consider how your loop "works", and which mv commands are executed.

For the first file, you executed

mv the_file "$(md5sum $i)"

but, since "$(md5sum "$i")" does NOT change as you loop, the command for the next file is:

mv the_2nd_file "$(md5sum "$i")"

replacing the first file. The first file is deleted, and its disk blocks are marked "free".

The same thing happens to the 3rd through Nth files. All that's left is the LAST file, now named "$(md5sum "$i")".

Do you have backups?

When writing powerful/dangerous commands to be applied to a bunch of files, use echo:

for f in * ; do
 echo mv $f "$(md5sum "$i")"
done

would have shown your error.

BTW, upper case [A-Z] variable names are traditionally used to communicate with applications. If you use lower case [a-z] names in your scripts, you'll never overlap.