Here is a solution I was able to get working:
#!/bin/bash
shopt -s nullglob
my_files='/root/temp/files'
old_name='essay'
new_name='new_name'
for file in "${my_files}/${old_name}"*; do
my_extension="${file##*.}"
mv "$file" "${my_files}/${new_name}.${my_extension}"
done
* `shopt -s nullglob`
This will prevent an error if the directory it's parsing is empty
* `for file in "${my_files}/${old_name}"*; do`
We are going to loop over every `file` in `/root/temp/files/` so long as it begins with `essay`
* `my_extension="${file##*.}"`
This will greedily trim anything up to the **last** `.` found in the filename (hopefully leaving you with only the extension)
* `mv "$file" "${my_files}/${new_name}.${my_extension}"`
This moves the old file to the new filename while reserving the extension. (rename)