MacOS – Using mv to rename files on terminal ended up with lost files

macosterminal

I'm on macOS Mojave 10.14.4, on a APFS SSD. Last week some students delivered me some image files over an image processing assignment. I have an automated routine on Matlab to grade the assignments, but it only loads files with a specific ".jpeg" extension.

Rather than rewrite my routine, I usually just rename the files (a mess of ".jpg", ".JPEG", ".JPG") on terminal. I'm used to do that on my University issued linux desktop. But that day I had my MacBook Pro with me, so I got them with it.

Alas, my terminal command "mv *.jpg *.jpeg" returned with a no such file or directory error, so I left this task for later. Earlier today I got to work after a three day weekend and when I opened the folder, I realized that about half of the files were missing.

My guess is that the mv didn't "fail properly" and, based on some thing that I've already looked around, may have lost the data for good! My Time Machine is at home, so it never got to back up those files.

I have already looked for possibly hidden folders where the files might have ended up, but no luck. Does anyone has any idea where the files may have gone? Or if they are truly lost?

Att.

Osmar

Best Answer

If you have a directory/folder of JPEG files that have either a .jpg and or .JPG extension and you want to change the extension to .jpeg, then in Terminal, use the following compound command after changing directory cd ... to the directory containing the JPEG files:

for f in *.[jJ][pP][gG]; do mv -n "$f" "${f%.*}.jpeg"; done